I am learning the same topics. I will try to answer this.
Two morphism agree on the overlap means they map the open subsets of the overlap to the same subsets in $Y$ and also they preserve the regular functions: $\pi_1^* \phi = \pi_2^* \phi$ on any open subsets of the overlap, for any regular function $\phi$ on $Y$, restricted on $\pi_i(U_1\cap U_2)$, where $\pi_i^* \phi =\phi \circ \pi_i$.
Define the morphism $\pi=\begin{cases}\pi_1 \text{ on } U_1\\\ \pi_2 \text{ on } U_2\end{cases}$
You have proved the continuity, so now it remains to prove for any open subset $V\subset Y$, $\phi\in O_Y(V)$ implies $\pi^*\phi \in O_X(\pi^{-1}(V))$.
We know that $(\pi|_{U_i\cap\pi^{-1}(V)})^*\phi \in O_X(U_i\cap\pi^{-1}(V))$ since $\pi|_{U_i\cap\pi^{-1}(V)}$ is a morphism. And $\pi^*\phi$ agrees on the intersection of $U_i\cap\pi^{-1}(V)$. By the gluing property for sheaves, $\pi^*\phi\in O_X(\pi^{-1}(V))$.
Hope this makes sense to you.