Mapping to unique nearest point
Notation: To avoid confusion between intervals and ordered pairs, $\langle a,b\rangle$ is an ordered pair.
With the usual metric on $\Bbb R^2,$ let $A=[0,1]\times \{0\}$ and $B= ([0,1)\times \{1\})\cup \{\langle 2,0\rangle \}. $ Let $X=A\cup B.$
If $0\leq t<1$ then $f(\langle t,0\rangle)=\langle t,1\rangle.$
But $f(\langle 1,0\rangle)=\langle 2,0 \rangle.$
So $f(x)$ is discontinuous at $x=\langle 1,0 \rangle.$ (See footnote). Note that $A$ and $B$ are closed in $X$.
The tricky part of constructing an example is that in any metric space $(X,d),$ if $X\supset B\ne \phi$ and $g(x)=\inf \{d(x,y):y\in B\}$ then $g:X\to \Bbb R$ $is$ continuous.
Footnote. The sequence $(\;f(\langle 1-1/n,0 \rangle)\;)_{n\in \Bbb N}$ does not converge to $f(\langle 1,0\rangle).$