Thank you for the comments, I will certainly take them to heart. According to the documentation
perldoc XML::Simple:
NoSort => 1 # out - seldom used
Newer versions of XML::Simple sort elements and attributes alphabetically (*), by default. Enable this option to suppress the sorting - possibly for backwards compatibility.
* Actually, sorting is alphabetical but 'key' attribute or element names (as in 'KeyAttr') sort first. Also, when a hash of hashes is 'unfolded', the elements are sorted alphabetically by the value of the key field.
Thank you for the code it will certainly come in handy.