Prove that a covering map is a homeomorphism

I got stuck in the following exercise:

Let $p:\widetilde{X}\rightarrow X$ be a covering map with $\widetilde{X}$ connected and $p^{-1}(x)$ finite, for every $x\in X$.

Show that if there exists a continuous map $f:\widetilde{X}\rightarrow\mathbb{R}$, injective in each fibre $p^{-1}(x)$ (that is, if $p(x)=p(y)$ and $f(x)=f(y)$ then $x=y$), then $p$ is a homeomorphism.

Clearly, we need to prove only that $p$ is injective, since it is already surjective, continuous and open.


Define $g : X \to \widetilde X$ by letting $g(x)$ be the point of $p^{-1}(x)$ on which $f$ is maximum. Since $f$ is injective on the fibres and the fibres are finite, $g(x)$ is well-defined. It is easy to see that $g$ is continuous, and so $g$ is a section of the covering map $p$. Since $\widetilde X$ is connected, this implies that $p$ is a homeomorphism (see this question for instance).

Question: Which topological spaces $Y$ have the property which $\mathbf R$ displays in this problem? I have no idea what the answer to this question might be, but it looks interesting. It breaks down to the property that every finite subset $S\subseteq Y$ has a "distinguished point" which varies continuously with $S$. For instance, does $Y=\mathbf R^2$ have this property?