Let $E$ be a Lebesgue measurable set in $\mathbb{R}$, with $m(E) < \infty$, then there exists a compact subset $K$ of $E$, s.t. $m(K)=\frac{1}{2}m(E)$.
My attempt: $\forall x \geq 0$, define a function $$f(x)=m(E \cap [-x,x]) \; .$$ For any $0 \leq x < y$, $$|f(x)-f(y)| \leq 2|y-x| \; ,$$ hence $f$ is continuous on $[0,\infty)$, since $$ f(0)=0 \;, f(\infty)=m(E) \; , $$ then by Intermidiate Value Thm., there exists $x_0 \in (0,\infty)$, s.t. $$m(E \cap [-x_0,x_0])=f(x_0)=\frac{1}{2}m(E) \; .$$ Since $E \cap [-x_0,x_0]$ is measurable, then for each $n \in \mathbb{N}$, there exists compact subset $K_n$ of $E \cap [-x_0,x_0]$, s.t. $$m((E \cap [-x_0,x_0])\setminus K_n) < \frac{1}{n} \; .$$ But we could not say $\lim_{n\rightarrow \infty}K_n$ is compact. Then I got stuck here.
The result is obvious of $m(E)=0$ so assume $0 <m(E) <\infty$. There exists a compact set $K_0 \subseteq E$ such that $\frac 1 2 m(E) <m(K_0) <m(E)$. Apply your argument with $E$ replaced by $K_0$. You will get $x_0$ such that $m([-x_0,x_0]\cap K_0)= \frac 1 2 m(E)$. Take $K=[-x_0,x_0]\cap K_0$.