First note that the proof of your "lemma" is easy.
For a bijective continuous map $f:X\to Y$ to be a homeomorphism, it is sufficient for $f$ to be a closed/open map, because then
$$
(f^{-1})^{-1}(A) = f(A)
$$
is closed/open for each $A \subset Y$, so that $f^{-1}$ is continuous, whence $f$ is a homeomorphism.
Now note that if $A \subset K$ is closed, where $K$ is compact, then $A$ is compact. Hence, so is $f(A)$. In a Hausdorff space, compact sets are closed, so $f(A)$ is closed, so that $f$ is a closed map.
But this does not proof invariance of domain. To see this, first note that your "proof" would note use the fact that $U \subset \Bbb{R}^n$ and $f : U \to \Bbb{R}^n$ (note that the dimensions match). But without matching dimensions, the theorem is not valid, as the following counterexample (taken from http://en.wikipedia.org/wiki/Invariance_of_domain#Notes) shows:
$$
f : (-1.1\, , \, 1) \to \Bbb{R}^2, x \mapsto (x^2 - 1, x^3 - x).
$$
The image of this function (also taken from the same post) is

It is an easy exercise to show that $f$ is not a homeomorphism onto its image although it is continuous and injective.
The problem here is that the claim you get is only that each restricted map $f|_K : K \to f(K)$ is a homeomorphism for $K \subset U$ compact. But this only gives you continuity of $f^{-1}|_{f(K)}$. But this does not entail continuity of $f^{-1}$ (as the example shows).