Yes. Suppose that $f(x)$ is not a.e. constant. Then there is subset $X$ of $\mathbb{R}$ such that $A:=f^{-1}(X)$ has positive measure but not full measure.
Note that for all $d\in D$, $\mu(A\Delta(A-d))=0$. Also, as $A$ and $\mathbb{R}\setminus A$ have positive measure, by the Lebesgue density theorem there are two points $x,y$ such that, for some small value of $\varepsilon$, $\mu(A\cap(x-\varepsilon,x+\varepsilon))>1.5\varepsilon$ and $\mu(A\cap(y-\varepsilon,y+\varepsilon))<0.5\varepsilon$.
However, there is a sequence $(d_n)_n$ in $D$ such that $x+d_n\to y$. And for all $n$ we have $$\mu(A\cap(x+d_n-\varepsilon,x+d_n+\varepsilon))=\mu((A-d_n)\cap(x-\varepsilon,x+\varepsilon))=\mu(A\cap(x-\varepsilon,x+\varepsilon))>1.5\varepsilon.$$
Thus, $\mu(A\cap(y-\varepsilon,y+\varepsilon))=\lim_{n\to\infty}\mu(A\cap(x+d_n-\varepsilon,x+d_n+\varepsilon))\geq1.5\varepsilon$, a contradiction.