The clearest way is to use the Unique Factorization Theorem. We give a proof that bypasses it.
Assume (it makes no difference) that $a$ and $b$ are positive. Let $d=\gcd(a,b)$. We want to show that $d=a$.
Let $a=da_0$ and $b=db_0$. Then $a_0$ and $b_0$ are relatively prime. From $a^2\mid b^2$ we conclude that $a_0^2\mid b_0^2$. Since $a_0$ and $b_0$ are relatively prime, from $a_0\mid b_0\cdot b_0$ we conclude that if $a_0$ does not divide (the first) $b_0$, it must divide the second. So $a_0\mid b_0$, and therefore $a_0=1$. Thus $a=d$, and we are finished.
Added: For completeness, we write down the Unique Factorization Theorem argument that shows that your $k$ is a perfect square. Let $b=p_1^{b_1}\cdots p_t^{b_t}$, where the $p_i$ are distinct primes. Then $b^2=p_1^{2b_1}\cdots p_t^{2b_t}$. Since $a^2$ divides $b^2$, all the prime divisors of $a^2$, and hence of $a$, are among the $p_i$. So $a=p_1^{a_1}\cdots p_t^{a_t}$, where some of the $a_i$ may be $0$. It follows that $a^2=p_1^{2a_1}\cdots p_t^{2a_t}$.
Divide. We find that $k=\frac{b^2}{a^2}=p_1^{2b_1-2a_1}\cdots p_t^{2b_t-2a_t}$. Since all the exponents of the $p_i$ in the factorization of $k$ are even, it follows that $k$ is a perfect square.