Homework: closed 1-forms on $S^2$ are exact.
Solution 1:
Your reasoning is spot on, but there are some annoying technical details to heed. I provided a proof in some greater generality.
If $U$ and $V$ are open subsets of a manifold $M$ with $H^1(U)=0$, $H^1(V)=0$ and $U\cap V$ connected, then $H^1(U\cup V)=0$.
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
$F(x)=\left\{\begin{array}{ll}f_1(x)&\text{ if }x\in U\\ f_2(x)+c&\text{ if }x\in V\end{array}\right.$
is smooth on $U\cup V$, and $dF=\omega$ by construction. So $\omega$ is exact on $U\cup V$, as desired.