Although Rigel’s answer solved the matter brilliantly, I would like to present an alternative solution to this:
Consider the sets $A_{\varepsilon,x} =\{ u > x, \, |f(u)-f(x)| < \varepsilon |u-x|\}.$
Notice that these sets are clearly open, by the continuity of $f$. Also, these sets are nonempty for every $x \in \mathbb{R}$, and $x \in \overline{A}\backslash A$ : indeed, as they are nested in $\varepsilon$, if one of them is empty/does not accumulate around $x$, every other one with $\eta < \varepsilon$ also is. Also, it means that we can assume without loss of generality that all points $y>x$ sufficiently close to $x$ satisfy
$$ f(y) \ge f(x) + \varepsilon(y-x).$$
Plugging this back into the property satisfied by $f$ gives us then a contradiction.
Claim: The set $A_{\varepsilon,x}$ is dense in $(x,+\infty).$
Proof: Suppose its intersection with an interval $(a,b)$ is empty, and consider $ a’ = \sup_{u<b} A_{\varepsilon,x} \le a$. It holds then for this $a’$ that
$$ |f(a’)-f(x)|\le \varepsilon (a’-x).$$
As the set $A_{\delta,a’}, \, \delta < \varepsilon,$ is nonempty and accumulates around $a'$, there is $b’\in (a’,b)$ such that
$$|f(b’)-f(a’)| < \delta(b’-a’).$$
This implies that
$$|f(b’)-f(x)| \le |f(b’)-f(a’)| + |f(a’)-f(x)| < \varepsilon (a’-x) + \delta(b’-a’) < \varepsilon (b’-x),$$
A contradiction to the definition of $a’. \, \square$
Now we finish: as the set $A_{\varepsilon,x}$ is open and dense in $(x,+\infty),$ it means that every point $y \in (x,+\infty)$ satisfies
$$ |f(y)-f(x)| \le \varepsilon(y-x).$$
This implies, in particular, that $f$ is differentiable at $x$ and that $f'(x) = 0.$ As this was valid for all $x \in \mathbb{R},$ we conclude that $f$ is differentiable and $f' =0,$ i.e., $f$ is constant, as desired.