Integral vanishes on all intervals implies the function is a.e. zero
The function $f$ must be integrable (one of $\int f^+$ or $\int f^-$ is finite) in order for the symbol $\int f$ to be defined. So, I'll assume this is the case. In fact, then, since $\int_0^a f$ exists and is finite for any $a$, it follows that $\int_c^d |f|<\infty$ for any numbers $c$, $d$.
We show $f$ is almost everywhere $0$ on any interval $[c,d]$; this will imply the desired result.
Suppose $f>0$ on the set of positive measure $E\subset[c,d]$. Choose a closed subset $F$ of $E$ with positive measure. We then have $\int_F f>0$. Now let $U=[c,d]\setminus F$. As $U$ is open, we may write $U$ as a disjoint union of open intervals: $U=\bigcup_{k=1}^\infty (a_k,b_k)$.
Now, since $\int_c^d |f|<\infty$ $$ 0=\int_{[c,d]}f=\sum_{k=1}^\infty\int_{a_k}^{b_k}f+\int_F f. $$ Since $\int_F f>0$, it follows that $\sum\limits_{k=1}^\infty\int_{a_k}^{b_k}f$ is negative. But then $\int_{a_n}^{b_n} f$ must be negative for some $n$. However, this proves untenable upon observing that $$ \int_{a_n}^{b_n} f =\int_0^{b_n} f - \int_0^{a_n} f =0. $$
Similarly, one can show $f$ cannot be negative on a set of positive measure.
Dynkin's $\pi-\lambda$ System theorem, as a strategic approach, works perfectly to conclude that the problem is true for all measurable sets !
Let $\mathcal{A}=$"set of intervals" which is a $\pi$-system and $\mathcal{L}=\{A\in\mathcal{F};\;\int_A f=0\}$ which is a $\lambda$-system. Hence, $$\mathcal{B}=\sigma(\mathcal{A})\subseteq\mathcal{L}$$ It means for each Borel-set $B$ : $\displaystyle \int_B f = 0$
Now use this fact that any measurable set differs from a Borel-measurable set by a Zero-set.
To finish the proof, see : Showing that $f = 0 $ a.e. if for any measurable set $E$, $\int_E f = 0$