It seems to me that in the global case the answer should be $no$ because of the following argument.
Set $S:=Spec$ $k[x,y,z]/(z^2-xy)$. Then $S$ is isomorphic to a quadric cone in $\mathbb{A}^3$ and the morphism $f \colon \mathbb{A}^2 \to S$ correspond to a double cover branched on the vertex of the cone and on a smooth conic.
Nevertheless, you can repeat the same construction by taking a double cover $f_k \colon Y_k \to S$ branched on the vertex of the cone and on a smooth curve of $even$ degree $2k$ not passing through the vertex. The fact that $f_k$ is branched at the vertex implies that $Y_k$ is smooth.
For $k=1$ we have $Y_1=\mathbb{A}^2$, $f_1=f$.
For $k=2$ we obtain an affine subset of a smooth surface of general type with $p_g=4, q=0, K^2=5$. These surfaces were studied by Horikawa in his famous paper "On deformations of quintic surfaces"; the double cover is actually the canonical map.
Of course $f_2$ does not factor through $f$, since they have the same degree but $Y_2$ is not isomorphic to $\mathbb{A}^2$.