Page is a not externally linkable
brotherhood_of_LAN - 9:51 am on Jul 5, 2011 (gmt 0)
I'm not sure why it's doing that, my version produces an altered document too, but all closing tags are removed. I tried looking around for feedback on it but no joy (took too long :o)).. if likely has a lot to do with the doctype and default settings for the DOM functions.
Change $dom->loadHTML to $dom->loadXML and the same for the save function, it should return the desired output.
There are a few decent comments in the manual but some trial and error can get you there too.