If $\operatorname{rank}A=2$, then $A=XY$ with $X,Y^T$ being $n \times 2$ matrices

Let $A$ be a $n \times n$ matrix with $\operatorname{rank}A=2$. Then there exist two $n \times 2$ matrices, $X$ and $Y^T$, such that $$A=XY^T$$

I have a proof, but I don't understand the following step. It uses the $n \times n$ matrix $$\overline{A}=\begin{pmatrix} 1 & 0 & 0 &\dots & 0 \\ 0 & 1 & 0 &\dots & 0 \\ 0 & 0 & 0 &\dots & 0 \\ 0 & 0 & 0 &\dots & 0 \\ \vdots \\ 0 & 0 & 0 &\dots & 0 \end{pmatrix}$$ and then uses the fact that there are two $n \times n$ invertible matrices $P,Q$ such that $A=P\overline{A}Q$.

Why is this true?

Outline:

Multiply $A\;$on the left by successive elementary matrices $E_1,...,E_k,\;$so as to transform $A\;$to row-reduced echelon form.

Let $P' = E_k\cdots E_1\;$be the product of those elementary matrices.

Then $P'\;$is invertible, and $P'A\;$is in row-reduced echelon form, with rank $2$.

Use a permutation matrix $Q'\;$to permute the columns of $P'A,\;$so as to yield$\;\overline{A}=P'AQ'$.

Then $A=P\overline{A}Q,\;$where $P=(P')^{-1}\;$and$\;Q=(Q')^{-1}$.

And from a conceptual point of view, thinking in terms of $A$ as a linear map: Fix a basis of the kernel (codimension $2$ subspace) and complete it to a basis $\mathcal B$ of $\mathbb R^n$. Then $Q$ stands for the change of basis from canonical to this new basis. Consider the basis $\mathcal B1$ in which the two vectors not belonging to the kernel are substituted by their images through $A$ (this is still a base by the way in which we constructed $\mathcal B$). Then $P$ is the matrix standing for the change of basis from $\mathcal B_1$ to canonical. The linear map represented by $A$ is then represented by $\overline A$ if you consider $\mathcal B$ as basis in the domain and $\mathcal B_1$ as basi in the codomain.