There are counterexamples.

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.

A simpler version of this example, without ordinals, is to take $X$ to be the positive integers, plus a sequence converging to each of them in the interval below. Specifically, let $X$ have points $k$ and also $k-\frac 1n$ for positive integers $k$ and $n$. Thus, $X$ is a countable closed subset of $\mathbb{R}$. Let $D$ be the isolated points $k−\frac1n$, and let $f$ be the function that interleaves successive convergent sequences into one. That is, for each adjecent pair of sequences, converging to $2n$ and $2(n+1)$, we map the isolated points of the sequences bijectively to the sequence converging to $n$. This is bijective on D, but extends continuously to $X$, and is not injective on $X$.

(I have removed the earlier flawed example.)

and$f_{|X\setminus D}:X\setminus D\to X\setminus D $ which is surjective. – Pietro Majer Oct 31 '11 at 11:49