Currently, I am doing some self-study in Real Analysis, and I wanted to verify if my proof regarding the irrationality of square roots of non-perfect squares is correct. I have viewed other solutions such as Proof verification: Prove $\sqrt{n}$ is irrational. but I wanted to see if my reasoning is sufficient here. Any comments explaining flaws in my reasoning are much appreciated!
$\textbf{Theorem:}$ Let $n\in \mathbb{N}$. Assume that $n$ is not a perfect square, meaning it cannot be written as the product of two identical integers. Then $\sqrt{n}$ is irrational.
$\triangle$ $\textbf{My proof:}$ For the sake of contradiction, assume that $\sqrt{n}$ is rational. Thus, $\sqrt{n}=\frac{p}{q}$ for $p,q\in \mathbb{Z}$, $q\neq 0$, and $p$ and $q$ are coprime (I assume without proof that any rational number can be written uniquely as a fraction of 2 coprime integers, but this is a known result). Squaring both sides gives us: $$n=\frac{p^2}{q^2} \Rightarrow p^2=nq^2$$ Also, note that $n\neq 0$ and $n\neq 1$ since both $0$ and $1$ are perfect squares.
$\textit{Lemma: If $p,q,n\in \mathbb{Z}$, $n\neq 0$, and $p^2=nq^2$, then $n$ is a factor of $p$ and $q$}:$
$\triangle$ Proof: Note, if $n=1$, this is trivially true, since $1$ is a factor of every number. Now, consider the case where $n\neq 1$. Since the integers are closed under multiplication (Again, I assume this without proof for brevity), $q^2$ and $p^2$ are both integers. Let $q^2=m$. Since $n \neq 0$, we can write $\frac{p^2}{n}=m$. Now, for the sake of contradiction, assume $n$ is not a factor of $p$. Thus, $\frac{p^2}{n}$ is an irreducible fraction. However, since $n\neq 1$, $\frac{p^2}{n}$ is not an integer (an integer cannot be an irreducible fraction with denominator other than 1), and thus $m\notin \mathbb{Z}$. However, we have $m\in \mathbb{Z}$ since it is the product of two (identical) integers. This is a contradiction, so $n$ must be a factor of $p$. Since this is the case, we can write $p=nk$ for $k\in \mathbb{Z}$. Thus, $p^2=n^2k^2$, which implies $n^2k^2=nq^2$. Divide both sides by $n$, and we have $q^2=nk^2$. Using the exact same argument I used for $p$, it follows that $n$ is also a factor of $q$. Thus, the lemma is concluded.
Now, the result of the lemma tells us that $p$ and $q$ share $n$ as a common factor, and that $n\neq 1$. However, we assumed that $p$ and $q$ were coprime, so this is a contradiction. Therefore, $\sqrt{n}$ is irrational.
Thanks to previous commentors for your suggestions!