Let $(X, \mathcal{B}, \mu)$ be a measure space and $f$ a measurable function on $X$ and suppose that $\forall E \in \mathcal{B}$ we have that $\int_E f = 0$. Then I want to show that $f = 0$ almost everywhere (a.e.).
Then $\{x : f(x) \ne 0\} = A$ is not measure zero so that either $\mu(A) > 0$ or $A \notin \mathcal{B}$.
Now if $\mu(A) > 0$ then it is easy to see that $\int_A f \ne 0$ so that we have a contradiction of our original hypothesis that $\forall E \in \mathcal{B}, \int_E f = 0$.
But if on the other hand $A \notin \mathcal{B}$, I cannot no longer appeal to $\int_A f \ne 0$ since $\int_A f$ is non-sense. So I’m having trouble with this part of the argument.
Arguing by contradiction definitely works, here’s the idea.
Let $\mu(\{ x : f(x) \neq 0 \}) > 0$.
Then we have $\{x : f(x) \neq 0\} = \{x : f(x) > 0\} \cup \{x : f(x) < 0\}$, so we must have one of these two sets have positive measure.
Let’s say its the first one (the argument for the second is analogous).
Then $\{x : f(x) > 0\} = \bigcup \{ x : f(x) \geq \frac{1}{n}\} = \bigcup E_n$ so again one of these must have positive measure.
So say $E_k$ has positive measure, then $f$ dominates $\frac{1}{k}$ on $E_k$ so $$\int_{E_k} f \geq \int_{E_k} \frac{1}{k} = \mu(E_k)\frac{1}{k} > 0.$$ So we have a contradiction.
EDIT: also, to comment on your proof: as you see here we don’t need to deal with whether or not $A$ is measurable, it definitely is. And also, for step $4$ of your proof $\mu(A) > 0$ does not imply that $\int_A f \neq 0$ for example if $f = 1_{(0,1)} – 1_{(-1,0)}$
The set $\{x:f(x)\neq 0\}$ is the same as $f^{-1}\big((-\infty,0)\big)\cup f^{-1}\big((0,\infty)\big)$ and therefore measurable. So the issue in 5. never occurs.
And I think you should be more explicit in step 4.