in reply to writing the data structure into a XML file (with high performance)

If the XML data is huge (or the resulting file will be huge...) then XML::Twig is particularly designed with this capability in mind.   It can process files in “chunks,” so to speak, in order to effectively deal with XML structures that are expected to be “too big to fit nicely in-memory.”   Just FYI ...