Can anyone check my proof below?
P. Let $X$ be a metric space. Prove that if $K\subseteq X$ is compact and $x\notin K$, there exist disjoint open sets $U$ and $V$ such that $K\subseteq U$ and $x\in V$.
S. Let $0<m<\inf\{d(k,x):k\in K\}$.
(We know that $0<\inf\{d(k,x):k\in K\}$ because if not, either $\exists k\in K$ such that $d(x,k)=0$, in which case $k=x\in K$, a contradiction, or $\forall \epsilon >0$, $\exists k_\epsilon\in K$ such that $d(k_e,x)<\epsilon$, in which case $x$ is a limit point of $K$. But since $K$ is compact, it is closed, so $x\in K$, contradiction.)
Then $\{N_m(k)\}_{k\in K}$ is an open cover of $K$, and in particular $U\triangleq\bigcup_{k\in K}N_m(k)$ is an open set containing $K$. Now, let $0<m^\prime<\inf\{d(x,k):k\in K\}-m$, and take $V=N_{m^\prime}(x)$. Then $U\cap V=\emptyset$.
The only thing I used compactness for is showing that $K$ is closed, which means this could've worked just fine for $K$ a closed set. This makes me feel like I have done something wrong, but I keep reading it and every step seems solid. I can't figure out what the problem is.
This is one of the separation axioms, which all metric spaces satisfy. The axiom being that for every closed set $E$ and a point $x$ not in $E$ then $E$ and $x$ have disjoint open neighborhoods. Such a space is usually said to be regular.
In a metric space you just take neighborhoods of radius $\epsilon/2$ with $\epsilon =d(x,E).$ This is essentially what you are doing.
So compactness is unnecessary, and I don't know what proof they expected that uses it. Variations of this separation axiom do only require $E$ compact, but it's superfluous here.