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$ has positive measure, by the [Lebesgue density theorem](https://en.wikipedia.org/wiki/Lebesgue%27s_density_theorem) for every $n\in\mathbb{N}$ there is some interval $I_n$ of length $l_n>0$ (we can assume $l_n\to0$ when $n\to\infty$) such that $\frac{\mu(I_n\cap A)}{\mu(I_n)}\geq1-\frac{1}{n}$. Thus, $\frac{\mu((I_n-d)\cap A)}{\mu(I_n)}=\frac{\mu(I_n\cap (A+d))}{\mu(I_n)}>1-\frac{1}{n}$ for all $d\in D$. As $D$ is dense, this means that for every interval $I$ of length $l_n$ we have $\frac{\mu(I\cap A)}{\mu(I)}\geq1-\frac{1}{n}$. But as $\mu(\mathbb{R}\setminus A)>0$, for big enough $n$ there must be intervals $I$ of length $l_n$ such that $\frac{\mu(I\cap(\mathbb{R}\setminus A))}{\mu(I)}>\frac{1}{2}$, a contradiction.