Hartshorne presents this result in Theorem I.3.2, but the proof is too much algebraic for me. I would like to really understand the reason of this isomorphism. So, suppose I consider an element $f\in\mathcal O(X)$; then for each $x_0\in X$ there is a neighbourhood $U_0$ of $x_0$ and polynomials $p,q$ with $q(x)\neq 0$ for every $x\in U_0$ satisfying
$$ f(x)= \frac{p(x)}{q(x)}, \qquad \forall x\in U_0. $$
If $x_1\in X$ is such that $U_0\cap U_1$ is non-empty, then of course
$$ \frac{p(x)}{q(x)} = \frac{p'(x)}{q'(x)} \Longleftrightarrow pq'-qp'\in I(U_0\cap U_1) . $$
At this point, I thought about using the compactness of $X$, so that finitely many neighbourhoods $U_i$ are necessary to be considered. Then, at the intersection $U=\cap_i U_i$ I get equalities
$$ p_i\prod_{l\neq i} q_l - p_j \prod_{l\neq j} q_l \in I(U), $$
but I do not think that is helpful, and if it is, I do not know how to continue. Any hints?
Remark. The most similar question I have found is this, which is solved in a comment by @reuns using an argument I do not understand. There is another one but its answer basically reproduces Hartshorne's reasoning.
EDIT:
Here is the theorem:
Let $X\subset A^k$ be an be an affine variety with affine coordinate ring $A(X)$. Then:
1.- $\mathcal O(X)\cong A(X)$.
2.- For each point $x\in X$, let $\mathfrak m_x\subset A(X)$ be the ideal of functions vanishing at $x$. Then $x\mapsto \mathfrak m_x$ gives a 1-1 correspondence between the points of $X$ and the maximal ideals of $A(X)$;
3.- for each $x$, $\mathcal O_x(X)\cong A(X)_{\mathfrak m_x}$ and $dim \mathcal O_x(X) = dim X$;
4.- $K(X)$ is isomorphic to the quotient field of $A(X)$, and hence $K(X)$ is a finitely generated extension field of $k$, of transcendence degree $= dim X$.
Addendum. After thinking more about it, I guess one can use the isomorphism provided in Theorem 4.4 for giving the corresponding variety whose coordinate ring is precisely the localisation. Still, I would like to get something even more explicit if possible.
Theorem 4.4 Let $X$ be an affine variety in $K^n$ given by a single equation $p=0$. Then $K^n\setminus X$ is an affine variety isomorphic to the one in $K^{n+1}$ with equation $x_{n+1}p-1=0$. Its affine ring is $K[x_1,\dots,x_{n}]_p$.
An answer?
After having thought even more about that and read otrher textbooks, I think my answer could be given by Shafarevich Basic Algebraic Geometry I, at page 47. The full reasoning should be the following:
We already know $f=p_x/q_x$ around each point, with $q_x(x)\neq 0$. Let $r_x$ be a polynomial such that $r_x(x)=1$ $r|_{X\setminus U_x} = 0$, and consider the ideal generated by all the elements $q_xr_x$. It is spanned by finitely many elements $q_1r_1,\dots, q_kr_k$. Moreover, it must be the ring itself, for if the system of equations
$$ q_1r_1 = \dots = q_kr_k = 0 $$ has a solution $x_0$, then every element in the ideal must vanish at that point, including the corresponding $q_{x_0}$ (that is what Shafarevich presents as the Hilbert Nullstellensatz theorem in Proposition A.9 at the appendix). Now, because of this, there are plynomials $h_1,\dots, h_k$ such that
$$ \sum_i q_ir_ih_i = 1. $$
WE can multiply by $f$ at both sides of this expression. Furthermore, because each term $q_ir_ih_i$ vanishes outside $U_i$, we can replace $f$ by its local expression there, getting
$$ \frac{p_1}{q_1}q_1r_1h_1 + \dots + \frac{p_k}{q_k}q_kr_kh_k = f, $$
and the result follows.
What do you think aboiut this?