That looks like part of a de filter grid. You need to take the filter apart, clean the grids well, replace any damaged grids and recharge with DE.
Since there is debris getting to the heater, there might be debris stuck in the heat exchanger blocking water flow.
Scale can also reduce water flow through the heat exchanger and reduce heat transfer.
Overheating water is more likely to scale.
In any case, if the internal bypass plunger is stuck open, that can cause the problem.
The gap seems a little bit small to create the problem, but it's possible
Let's see what happens when you get it put back together.
Make sure that the flow is good.