[tex]\dfrac fg=\dfrac{(x-1)^2}{(x+2)^2}[/tex]
[tex]\implies f=g\dfrac{(x-1)^2}{(x+2)^2}[/tex]
[tex]\implies f^2=fg\dfrac{(x-1)^2}{(x+2)^2}[/tex]
[tex]\implies f^2=x^2\dfrac{(x-1)^2}{(x+2)^2}[/tex]
[tex]\implies\sqrt{f^2}=\sqrt{x^2\dfrac{(x-1)^2}{(x+2)^2}}[/tex]
[tex]\implies|f|=\left|\dfrac{x(x-1)}{x+2}\right|[/tex]
Similarly, we can show that
[tex]|g|=\left|\dfrac{x(x+2)}{x-1}\right|[/tex]
Then from here we can solve for [tex]f[/tex] or [tex]g[/tex] by taking either to be both positive, or both negative. That is,
[tex]f(x)=\dfrac{x(x-1)}{x+2},\,g(x)=\dfrac{x(x+2)}{x-1}[/tex]
or
[tex]f(x)=-\dfrac{x(x-1)}{x+2},\,g(x)=-\dfrac{x(x+2)}{x-1}[/tex]
(Note that this is only true for [tex]x\neq1[/tex], [tex]x\neq-2[/tex], and [tex]x\neq0[/tex].)