Your DOM document in the iframe is clearly an XMLDocument, not an HTMLDocument.
When you remove the xmlns attribute, you change the DOM document such that it is unserializable as XML.
"outerHTML" is a serialization operation, so to write the DOM out as XML, it needs to be repaired first, which restores the attribute to the XML.
You have two options. Implement your own serializer of the DOM that repairs the output in a different way, or remove the attribute from the XML after serialization as Mr Lister suggests in the comments.