# Why do we need compactness?

There's a theorem that says if $E$ is an infinite subset of a compact set $K$, then $E$ has a limit point in $K$.

Why can it not be done with $K$ only being closed? If $K$ is closed then $\overline{E} \subset K$, so if $x$ is a limit point of $E$, then $x \in \overline{E} \implies x \in K$.

As a counterexample: $\Bbb R$ is closed, and $\Bbb Z$ is an infinite subset of $\Bbb R$. However, $\Bbb Z$ has no limit points.
Your conclusion fails because you assumed that $x$, a limit point of $E$, exists.