I am trying to find out how morphisms from open subsets of affine varieties to projective spaces look like, so I want to consider
$f: U \rightarrow \mathbb{P}^n$
for $U\subset \mathbb{A}^m$ open. For simplicity, consider $n=1$. Then by the definition of the structure sheaf of the projective space, such a set theoretic map $f$ is a morphism if and only if $f|_{f^{-1}(U_i)}$ are morphisms for the standard affine patches $U_0$ and $U_1$. Since $U_i \simeq \mathbb{A}^1$, these are given by polynomials $g_0,g_1\in \mathcal{O}_{\mathbb{A}^m}(U)$. By embedding $\mathbb{A}^1$ in $\mathbb{P}^1$ as $U_0$ and $U_1$ respectively, we can then view $f$ as $x\mapsto [1:g_0(x)]$ or $x\mapsto [g_1(x):1]$ on $f^{-1}(U_0)$ and $f^{-1}(U_1)$. But I found in serveral sources that we can always write such a morphisms as $x\mapsto [f_1(x),f_2(x)]$ where $f_1$ and $f_2$ have no common zeros, and I fail to see how that follows from my discussion. Maybe one can show that every morphism from $\mathbb{A}^1$ to $\mathbb{P}^1$ factors through $\mathbb{A}^2$, then this result would follow trivially, but I do not know a proof for that either.
Your analysis is not correct. The key error is your claim that the two maps $f|_{f^{-1}(U_i)}:f^{-1}(U_i)\to U_i$ are determined by two elements $g_0,g_1\in\mathcal{O}_{\Bbb A^m}(U)$: there's no reason that $f^{-1}(U_i)$ should be $U$. Instead, the maps are determined by $g_0\in\mathcal{O}_{\Bbb A^1}(f^{-1}(U_0))$ and $g_1\in\mathcal{O}_{\Bbb A^1}(f^{-1}(U_1))$ with the conditions that $f^{-1}(U_0)\cup f^{-1}(U_1)=U$ and $g_0|_{f^{-1}(U_0)\cap f^{-1}(U_1)}=g_1|_{f^{-1}(U_0)\cap f^{-1}(U_1)}$.
Once we correct this error, it's easy to get to the statement you want. Writing $g_0$ as $\frac{p_0}{q_0}$ where $p_0,q_0\in k[x]$ are relatively prime, we can write $[1:g_0]=[1:\frac{p_0}{q_0}]=[q_0:p_0]$ and we have written our morphism in the form you're after.