Yes, I completely replaced all Silverstripe folders. I have no other modules installed, only custom code for extending Page and Form. I don't think I can remove my page types, run dev/build and keep the content intact? But I think I found out why the HTML structure is continuously growing, at least I think it is closer to the actual problem. I will explain.
if($("#FolderImages").length > 0 && $("body.CMSMain").length > 0) loadImages(false);
I will make a new copy of the 2.3.7 installation and upgrade it to see if the same problem occurs again. If it does, I'll remove any custom code and start from there as you suggested Ryan. Thanks for the tip.