The claim you are trying to prove is false. Below is an example in the case when both $K$ and $L$ are unbounded. [What I wrote initially was an attempt to simplify my example and I simplified it so much that $X$ became connected.]
The idea is that if $X$ is a metrizable topological space then the space $Q$ of connected components of $X$ equipped with the quotient topology, need not be Hausdorff. In particular, two elements $q_1, q_2\in Q$ may fail to be separated by a partition of $Q$ into two clopen subsets.
Now, the example. Let $K$ and $L$ be, respectively, the vertical lines $x=1, x=+1$ in the xy-plane. Let $G_n$ be a sequence of pairwise disjoint "U-shaped curves" in the strip $-1<x<1$, such that each $G_n$ is homeomorphic to ${\mathbb R}$ and equals the union of the two vertical rays $x=\pm(1 -\frac{1}{n}), y\ge -n$ and the horizontal interval
$$
-1+\frac{1}{n}\le x\le 1 -\frac{1}{n}, y=-n.
$$
(I might draw a picture if and when I have time.)
Let
$$
X:= K\cup L \cup \bigcup_{n\in {\mathbb N}} G_n.
$$
This space is clearly disconnected. Furthermore, $K, L, G_n (n\in {\mathbb N})$ are its connected components. On the other hand, suppose that $X=Y\sqcup Z$ is a partition of $X$ in two closed subsets containing $K$ and $L$ respectively. If $Y$ contains infinitely many of the curves $G_n$ then its closure contains both $K$ and $L$, which is impossible. Similarly, $Z$ cannot contain infinitely many of the curves $G_n$. Hence, $Y\cup Z$ cannot equal the entire $X$.
You can see that the space $Q$ of connected components of $X$ consists of two points $[K], [L]$ and a sequence $[G_n]$ which converges to both $[K]$ and $[L]$, making $Q$ non-Hausdorff.
Edit. Now, your modified question, has positive answer.
I will need the notion of a quasicomponent of a topological space. Recall that a subset of a topological space is called clopen
if it is both closed and open. The quasicomponent $X_x$ of a point $x$ in a topological space $X$ is the intersection of all
clopen subsets containing $x$. Equivalently, quasicomponents of $X$ are the equivalence classes of the equivalence relation
$\sim$ on $X$, where $x\sim y$ if and only if there is no partition of $X$ in tow clopen subsets, one containing $x$ and the other containing $y$.
The component $C_x$ of $x$ in $X$ is always contained in the quasicomponent $X_x$, but, quasicomponents, are, in general, strictly larger than components. However, if $X$ is compact and Hausdorff, then quasicomponents in $X$ are equal to components, see for instance here.
Proposition. Suppose that $X$ is a compact Hausdorff topological space. Then for any two distinct quasicomponents $A, A'$ of $X$ there exist clopen subsets $U, U'\subset X$ such that
$$
A\subset U, A'\subset U', X=U\sqcup U'.
$$
Proof. By the definition of a quasicomponent, for any two points $a\in A, a'\in A'$ there exists a pair of disjoint
clopen subsets $U, U'\subset X$ such that $a\in U, a'\in U'$ and $X=U\cup U'$. By connectedness of $A, A'$, it follows that
$A\subset U, A'\subset U'$. Clearly, both $U, U'$ are clearly also closed. qed
Back to your original question, where $K$ is a compact connected component of a closed subset $X\subset R^n$ and $L$ is another component of $X$. If $X$ is compact, then simply use the above theorem. Suppose that $X$ is noncompact.
Lemma. $K$ is a quasicomponent of $X$.
Proof. Let $B$ be a sufficiently large closed round ball in $R^n$ whose interior contains $K$. Then $K$ is a component of $X_B:=B\cap X$, hence, a quasicomponent of $X_B$. Hence, $K$ is the intersection of all its clopen neighborhoods in $X_B$. By compactness
of $K$, one of these clopen neighborhoods $U$ will be contained in the interior of $B$. Hence, $U$ is also clopen in $X$. Therefore,
all clopen neighborhoods of $K$ in $X_B$ which are contained in $U$ are also clopen in $X$. Hence, $K$ equals the intersection of its clopen neighborhoods in $X$. qed
Lemma. Let $X$ be a closed subset of $R^n$, let $K, L$ be distinct connected components of $X$, where $K$ is compact.
Then there exists a pair of clopen subsets $U, V\subset X$ such that
$$
K\subset U, L\subset V, X= U\sqcup V.
$$
Proof. We just proved that $K$ is a quasicomponent of $X$. Since $L$ is connected and distinct from $K$, and $K$ is the intersection of its clopen neighborhoods, one of the clopen neighborhoods (say, $U$) of $K$ in $X$ will be disjoint from $L$. Thus, for $V:= X- U$, we obtain:
$$
K\subset U, L\subset V, X= U\sqcup V
$$
and $U, V$ are closed. qed