Here is a counterexample. Let $X$ be the ordinal $\omega^2+1$, which as a topological
space is the same as infinitely many convergent sequences,
whose limit points converge. This space is homeomorphic to
a countable closed subset of the unit interval and is
therefore completely metrizable.

Let $D$ be the isolated points of $X$, which is exactly the
set of successor ordinals below $\omega^2$. This is dense,
since the closure adds the missing limit ordinals. Let $f$
be the function that interleaves two successive sequences
together into one. That, we combine the successor ordinals
in the interval $[\omega\cdot 2n,\omega\cdot 2(n+1))$ to those in
$[\omega\cdot n,\omega\cdot(n+1))$ by an injective function
that simply interleaves the two sequences into one. This is
injective on $D$ and also surjective. The function $f$
extends continuously to $X$ by mapping the limit points of
the successive sequences, $\omega\cdot2n$ and
$\omega\cdot2(n+1)$ both to $\omega\cdot n$, and
$\omega^2\mapsto \omega^2$. Note that the extension $f$ is
not injective.