Here's an example. First take a countable family $\lbrace A_n:n\in\mathbb{N}\rbrace$ of countable dense sets in $(0,1)$ and then let $f:[0,1]\to\[0,1]$ be continuous such that for each $n$ the maps $f$ is an order-isomorpism between $A_n\cap(0,1/1)$ onto $A_{2n}$ and an order-reversing isomorphism between $A_n\cap(1/2,1)$ and $A_{2n+1}$. Thus $f$ is a bijection between $D=\bigcup_{n]1}^\infty A_n$ and itself, but it is not injective on $[0,1]$. The map $f$ is readily constructed, first recursively on $D$ and then by continuous extension to all of $[0,1]$.
Addendum: to construct the restriction of $f$ to $[0,1/2]$ modify Cantor's proof of the uniqueness of $\mathbb{Q}$ to construct an order-isomorphism $g$ between $D\cap(0,1/2)$ and $E=\bigcup_{n=1}^\infty A_{2n}$ that maps $A_n\cap(0,1/2)$ onto $A_{2n}$ for each $n$. Then define $f(x)=\sup\lbrace g(d):d\in D, d < x \rbrace $. Define $f$ on $[1/2,1]$ in a similar fashion.
Another addendum: I missed/overlooked the condition that $D=f^{-1}[D]$; my map is a bijection from $D$ to itself and that's it. The near-homeomorphisms on the square settle it nicely. In the spirit of those constructions one can get a one-dimensional example on the $\sin\frac1x$-curve: in every arc between points with coordinates $((n+\frac12)\pi)^{-1}$ and $((n+\frac32)\pi)^{-1}$ shrink the interval of points with $y$-coordinates between $-1/2$ and $1/2$ to the interval $[-1/n,1/n]$, everything in a bijective way. Then on the limit segment $\lbrace0\rbrace\times[-1,1]$ the interval $[-1/2,1/2]$ is collapsed to a point. Here $D$ is the graph of $\sin\frac1x$ of course.