First, you should convince yourself that the question whether a given morphism $\operatorname{Spec} \mathcal{O}_{X,x} \to Y$ extends to an open neighborhood of $x$ comes down to the following question in commutative algebra:
Let $A$ and $B$ be two rings and let $\mathfrak{p}$ be a prime ideal of $A$. Does a given ring homomorphism $B \to A_\mathfrak{p}$ factor as $B \to A_f \to A_\mathfrak{p}$ for some $f \in A \setminus \mathfrak{p}$?
Note that there is no reason to hope that such a factorization always exists. Indeed, the answer to the above question might be "no".
But what if $B$ is a finitely generated $R$-algebra with $R$ a Noetherian ring, $A$ is an $R$-algebra and the given morphism is a morphism of $R$-algebras? This is the case you have to deal with in solving your exercise (I'll assume you are able to work out why - if you have trouble, just drop a comment). Then the above question is guaranteed to have a positive answer. Let's prove this. Write $B = R[T_1,\dotsc,T_n] / (g_1,\dotsc,g_m)$, denote the composite of the canonical projection $R[T_1,\dotsc,T_n] \twoheadrightarrow B$ with the given morphism $B \to A_\mathfrak{p}$ by $\varphi$ and write
$$\varphi(T_i) = \frac{a_i}{f_i}, \quad i=1,\dotsc,n \, ,$$
$$\varphi(g_j) = \frac{a_j'}{h_j}, \quad j=1,\dotsc,m \, .$$
Now, for each $j \in \lbrace 1,\dotsc,m \rbrace$, choose some $f_j' \in A \setminus \mathfrak{p}$ such that $f_j' a_j' = 0$ in $A$ (which exists since $\varphi(g_j) = 0 \in A_\mathfrak{p}$). I now claim that $f = \prod_{i=1}^n f_i \prod_{j=1}^m f_j'$ has the desired property, i.e. that the given homomorphism factors through $A_f \to A_\mathfrak{p}$. To see why, we first make use of the fact that, by construction, $f$ is a common denominator of all the $\varphi(T_i)$ and note that
$$ T_i \mapsto \frac{a_i \prod_{k \neq i} f_k \prod_{j=1}^m f_j'}{f}, \quad i=1,\dotsc,n$$
defines a morphism of $R$-algebras $R[T_1,\dotsc,T_n] \to A_f$ whose composite with $A_f \to A_\mathfrak{p}$ agrees with $\varphi$. In addition, we have, by construction, $a_j' f = 0$ for all $j \in \lbrace 1,\dotsc,m \rbrace$; thus, the morphism just defined maps each $g_j$ to $0$ and, as a consequence, factors over $B$.
Best Answer
Maybe it is better to see the construction this way: a map from $\operatorname{Spec}(K)$ to $X_k$ gives a closed point $x$ of $X_K$. The underlying topological space of $\operatorname{Spec}(O_K)$ has two important points: a generic point coming from $\operatorname{Spec} K$ and a closed point $s$. So if we want to extend the map from $\operatorname{Spec}(K)\to X_K$ to a map $\operatorname{Spec}(O_K)\to X$ we have to send the generic point of $\operatorname{Spec}(O_K)$ to $x$ and because we want the continuity on topological spaces we have to send $s$ to a point in the closure of $x$ for example $z$. so topologically the image of our map must be in $Spec(O_{\bar{\{x\}},z})\subset Spec X$
Now that we know map on topological space for knowing the map between schemes we only have to give a map between $O_z\to O_K$ extending the morphism between $O_x\to K$. The proof in Liu's book uses the definition of properness to give such a map: in fact both ring are isomorphic:we have the map $Spec(O_z)\to Spec(O_K)$ we know that the generic point is in the image of this map and by properness the image is closed so this map is subjective on topological space and hence coming from a dominating map between local ring but both of this ring have the same field of fraction(because we know we have a map $$O_z\to K$$) and by general properties of valuation ring the map must be an isomorphism so its inverse is the extension we want. note that we never used openness of generic point in the proof.