From the 2008 UCLA Geometry-Topology qualifying exam:
let $\theta$ be a $1$-form on $S^2$ with $d \theta = 0$. Construct a function $f$ on $S^2$ with $d f = \theta$.
I'm not very confident in my ability to answer even a basic problem like this properly, and I'd appreciate someone telling me if I'm mistaken in my reasoning.
I argued as follows:
let $U$ be the subset $S^2\setminus\{\text{south pole}\}$ and $L=S^2\setminus\{\text{north pole}\}$.
Since these subsets are diffeomorphic to $\mathbb{R}^2$ via stereographic projection, the restriction of $\theta$ to either one of $U$ or $L$ is exact.
Thus there exist $f_U$ and $f_L$ so that $d f_U = \theta , d f_L = \theta$ on $U,L$ respectively.
On the intersection $U\cap L$ we have $d f_U = d f_L$, that is $d(f_U-f_L) = 0$.
This forces $f_U = f_L + c$ for some constant $c$ on their common intersection.
The existence and choice for $f$ are now apparent: let $f=f_U$ on $U$ and $f(\text{south pole}) = f_L(\text{south pole})+c$.
Best Answer
Your reasoning is spot on, but there are some annoying technical details to heed. I provided a proof in some greater generality.
It suffices to show that every closed $1$-form on $U\cup V$ is exact. To this end, let $\omega$ be a closed $1$-form on $U\cup V$. Let $\iota_V$ and $\iota_U$ denote the canonical inclusions of $V$ and $U$ into $U\cup V$, respectively. Since the exterior differential commutes with pullback, it follows that $d\iota_{U}^*\omega=\iota_{U}^*d\omega=0$ and, likewise, $d\iota_{V}^*\omega=\iota_{V}^*d\omega=0$. So $\iota_{U}^*d\omega$ and $\iota_{V}^*d\omega$ are closed. But $H^1(V)$ and $H^1(U)$ are trivial, and hence very closed $1$-form on $U$ and $V$, respectively, are exact. That is to say, there exist functions $f_1:U\to \mathbb{R}$ and $f_2:V\to \mathbb{R}$ so that $df_1=\iota_{U}^*\omega$ and $df_2=\iota_{V}^*\omega$. Now, as $U\cap V$ is connected, we have that $f_1\mid_{U\cap V}$ and $f_2\mid_{U\cap V}$ are cohomologous, as $d(f_1-f_2)=df_1-df_2=0$. Since $U\cap V$ is connected, and $d(f_1-f_2)=0$, it follows that $f_1-f_2=c$ for some constant $c$. Thus, the map $F:U\cup V\to \mathbb{R}$ given by
is smooth on $U\cup V$, and $dF=\omega$ by construction. So $\omega$ is exact on $U\cup V$, as desired.