Here is an attempt at a proof, first prove it for a locally integrable $f$ and then extend it to measurable $f$ (with additional requirement that it is finite ae)
define $C=\int_0^1 f(t)dt$,
for $x>0$,$g(x)=\int_0^x f(t)dt$
pick $a$ such that $ax=1$
$g(x)=\int_0^x f(t)dt=\int_0^x f(at)dt=x(ax)^{-1}\int_0^x f(at)adt=x\int_0^1 f(y)dy$
Therefore $g(x)=Cx$
so $g'=f=C$ ae on $(0, \infty)$
now for a measurable $f$ , the set $A_n=\{x : |f(x)| < n \}$ is measurable,where $n \in N$, define $f_n=f1_{A_n}$ where $1_{A_n}$ is indicator function for set ${A_n}$. Then $f_n(x)=f_n(ax)$ for almost every $ x \in A_n $ Using similar trick as before, $f_n=C_n$ for almost every $x \in A_n$ where $C_n=\int_0^1 f_n(t)dt$
Now whenever $\mu (A_n) > 0$ , we have $f(x)=C_n=C_{n+1}=C_{n+2}....=C_{\infty}$ for almost every $x \in B=\bigcup A_n$
Now to finish the proof I have to assume $\mu(B^c \bigcap [0,\infty))=0$ which is true if $f$ is finite ae
The above trick does not work once we drop the requirement of $ f $ being finite ae.