Why does H2O electrolysis produce O2 on the anode instead of H2O2
It does, as an intermediate product. The peroxide formed is on the surface of the electrode which changes it's chemical behavior.

Electrolysis is a four-electron process. In the first step, an electron is removed from a water molecule, producing a neutral OH adsorbed to the surface of the electrode. The second step removes another electron from the adsorbed OH, producing a neutral oxygen atom adsorbed to the electrode. Third, another electron is removed from a water molecule leaving an adsorbed OOH. Then the fourth electron comes from the OOH to produce O2.

My understanding is that the interactions with the electrode partially stabilize the unstable intermediate states. This is the reason some electrodes work better than others as catalysts.

This paper has more than you'll ever need to know: https://doi.org/10.1002/cctc.201000126