I have stumbled upon the following Lemma in Hartshorne exercise II.6.3(a).
Let $X$ be a noetherian, integral, separated scheme which is regular in codim 1. Let $Z_i$ be prime divisor of $X$, s.t. $\left\{U_i=X-Z_i\right\}_i$ forms an open cover of $X$. Let $D$ a divisor on $X$. Suppose that $\left.D\right|_{U_i}=\operatorname{div}_{U_i}(f)$ is the principal divisor on $U_i$ determined by a common $f$. Then $D=\operatorname{div}_X(f)$ is the principal divisor on $X$ determined by the same $f$.
I want help in proving it. It is probably something trivial that I can't see. The author of this problem said it is proven just by unwinding the definitions. It didn't help me prove this. I have tried to use the exact sequence proposition II.6.5 in Hartshorne $$\mathbf{Z} \rightarrow \mathrm{Cl} X \rightarrow \mathrm{Cl} U_i \rightarrow 0$$ To deduce that $D-(f)=n_i Z_i$ for some $n_i \in \mathbb{Z}$, and this equality holds for all $i$. I can't seem to find a reason to deduce that $n_i=0$.
Note here we are showing equality of divisors and not linear equivalence. The map of free abelian groups $\pi: \operatorname{Div}(X) \to \operatorname{Div}(U_i)$ is given on prime divisors by
$$\pi(Z) = \begin{cases} Z \cap U_i & Z \cap U_i \neq \emptyset \\0 & Z \cap U_i = \emptyset. \end{cases}$$
Of course, the only prime divisor sent to zero is $Z_i$.
Hence, in this case, we actually have a short exact sequence $$0 \to \mathbb{Z}\cdot Z_i \to \operatorname{Div}(X) \to \operatorname{Div}(U_i) \to 0.$$
Now, as you stated, this implies that $D - \operatorname{div}(f) = n_iZ_i$ for each $i$. This cannot be unless $n_i = 0$. Indeed; pick $j \neq i$, then $(D - \operatorname{div}(f))|_{U_j} = n_i (Z_i \cap U_{j}) = 0$. Since $(Z_i \cap U_j)$ is a free generator of $\operatorname{Div}(U_j)$, it follows that $n_i = 0$.