First note that the result is true if the support of $\varphi$ is disjoint from $E$; this follows from integration by parts.
Next note that every algebraic set is a finite union of smooth submanifolds (of possibly different dimensions). So let's first prove this for smooth submanifolds.
Throughout let $K_\varphi$ be the support of $\varphi$, which is compact.
For a closed set $K$, denote by $d_K$ the distance function to $K$.
$\dim(E) \leq n - 3$
Let $E$ be a smooth submanifold of dimension $\leq n -3$. Then in a tubular neighborhood $U$ of $E$, we have that the squared distance function to $E$ is smooth. Let $\chi$ be a fixed bump function on the real line that equals $1$ on $[-1,1]$ and $0$ outside $[-2,2]$.
For $\epsilon > 0$, split
$$\varphi(x) = (1 - \chi(\epsilon^{-2}d_E^2(x)) \varphi(x) + \chi(\epsilon^{-2}d_E^2(x)) \varphi(x) $$
The first factor is supported away from $E$ and so we will ignore.
For the second factor we can compute its Laplacian to be of size
$$ O(\epsilon^{-2}) $$
But as $\dim(E) \leq n - 3$, the set $\{x\in K: d_E(x) < \epsilon\}$ has volume $O(\epsilon^3)$. This means that
$$ \int u \triangle (\chi(\epsilon^{-2}d_E^2)\varphi) = O(\epsilon) $$
is negligible as we take $\epsilon\searrow 0$.
A consequence for our original problem, where $E$ is an algebraic set, is:
For every $\epsilon > 0$, there exists open sets $U, V$ with $\bar{U}\subseteq V$ and a smooth function $\eta$ that equals $1$ in $U$ and $0$ outside $V$, such that
- $\left|\int u \triangle (\eta \varphi)\right| < \epsilon$ and $\left| \int \eta\varphi \right| < \epsilon$
- $E \cap (\bar{U})^c$ is a finite union of $n-2$ dimensional smooth manifolds.
Note that for these arguments we just need that $u\in L^\infty_{loc}$, and not any assumption of continuity.
$\dim(E) = n-2$
The previous argument doesn't work, as the volume of the $\epsilon$-tubular neighborhood of $E$ is now size $\epsilon^2$. So here we use Lipschitz continuity.
The details are a bit annoying to write out, but here's the sketch:
- Since $\bar{E}\cap K_\varphi$ is compact, we can cover it by finitely many small balls on each of which $u$ is approximately constant. Take a partition of unity. This allows us to split $\varphi$ into a part that is far from $E$ (where the result is already know to be true) plus finitely many parts where $u$ is almost constant. Denote by $\tilde{\varphi}$ the smoothly truncated function to one of these small balls.
- On each small part we have
$$ \int u \triangle\tilde{\varphi} = \int (u-u_0) \triangle\tilde{\varphi} + \int u_0 \triangle \tilde{\varphi} $$
the second factor vanishes since it is the integral of the Laplacian of a compactly supported function against a constant.
- For the first factor we estimate as in the previous section. One part is far from $E$ and hence can be treated trivially. For the other part we use that $\triangle(\chi(\epsilon^{-2} d_E^2)\tilde{\varphi})$ is of size $\epsilon^{-2}$, and that the tube has volume $\epsilon^2$, to conclude that the corresponding integral is bounded by $O(|u-u_0|)$.
- Continuity of $u$ then finishes the task.