$\def\sK{\mathcal{K}}\def\sO{\mathcal{O}}$Let $X$ be a integral scheme, denote $K(X)$ to the function field of $X$ and $\sK_X$ to the $\sO_X$-module constantly $K(X)$.
In Görtz, Wedhorn, Algebraic Geometry I, 2nd ed., pp. 301-302, one finds:
Definition 11.20. A Cartier divisor $D$ on the integral scheme $X$ is given by a tuple $\left(U_i, f_i\right)$ where the $U_i$ form an open covering of $X$ and where $f_i \in K(X)^{\times}$ are elements with $f_i f_j^{-1} \in \Gamma\left(U_i \cap U_j, \mathscr{O}_X^{\times}\right)$ for all $i, j$. Two tuples $\left(U_i, f_i\right),\left(V_i, g_i\right)$ give rise to the same Cartier divisor, if $f_i g_j^{-1} \in \Gamma\left(U_i \cap V_j, \mathscr{O}_X^{\times}\right)$ for all $i, j$.
(...)
There is a close relationship between divisors and line bundles. To a Cartier divisor $D$ we attach the line bundle $\mathscr{O}_X(D)$, given by $$ \Gamma\left(V, \mathscr{O}_X(D)\right)=\left\{f \in K(X) ; f_i f \in \Gamma\left(U_i \cap V, \mathscr{O}_X\right) \text { for all } i\right\} $$ for $V \subseteq X$ open. Over $U_i, \mathscr{O}_X(D)$ is isomorphic to the free $\mathscr{O}_{U_i}$-submodule of rank $1$ of $\sK_{U_i}$ generated by $f_i^{-1}$.
I am trying to understand the last claim: Why $\sO_X(D)|_{U_i}\cong\sO_{U_i}f_i^{-1}\subset\sK_{U_i}$? (Here by “$\sO_{U_i}f_i^{-1}$” I mean the smallest $\sO_X$-submodule of $\sK_{U_i}$ containing $f_i^{-1}$; which exists by 01AP.)
$\def\sO{\mathcal{O}} \def\sK{\mathcal{K}}$Let $f\in K(X)$ and $V\subset U_i$ be open. I claim that $f\in\Gamma(V,\sO_X(D))$ if and only if $f_if\in\Gamma(V,\sO_X)$. The implication to the right is clear. Conversely, if $f\in\Gamma(V,\sO_X(D))$ holds, then $f_i^{-1}f_jf_if\in\Gamma(\underbrace{U_j\cap U_i\cap V}_{U_j\cap V},\sO_X)$ for all $j$.
We will show that we have an actual equality $\sO_X(D)|_{U_i}=\sO_{U_i}f_i^{-1}$ as subsheaves of $\sK_{U_i}$. Given $V\subset U_i$ open, we must show that $\Gamma(\sO_X(D),V)=\Gamma(\sO_{U_i}f_i^{-1},V)$. It suffices to show it for $V$ affine. It holds $\sO_{U_i}f_i^{-1}|_V=\sO_Vf_i|_V^{-1}$ (for they have same stalks, 01AR). Note that $\sO_{U_i}f_i^{-1}$ is quasi-coherent: since $\sK_X(V)=\operatorname{Frac}(\sO_X(V))$ (02OW (5)), we have that $\sO_{U_i}f_i^{-1}|_V$ is the $\sO_V$-tildification of the $\Gamma(V,\sO_V)$-module $\sO_X(V)f_i^{-1}$, for they have same stalks.
In conclusion, given $f\in K(X)$, we have $f\in\Gamma(V,\sO_X(D))$, i.e., $f_if\in\sO_X(V)$, if and only if $f\in \sO_X(V)f_i^{-1}\subset\sK_X(V)$, i.e., $f\in\Gamma(V,\sO_{U_i}f_i^{-1})$.
Lastly, $\sO_X(D)|_{U_i}=\sO_{U_i}f_i^{-1}$ is free on $f_i^{-1}$ since the $\sO_{U_i}$-linear map $\sO_{U_i}\to\sO_{U_i}f_i^{-1}\;(\subset\sK_{U_i})$ sending $1$ to $f_i^{-1}$ is an isomorphism: this can be seen locally and in particular when restricting to an open affine $V\subset U_i$. It then follows from the discussion above.