XmlBeans.save()
uses toString()
to get the XML string, which is not formatted. Due to this the string in your file is unformatted as well. For formatted output do the following:
XmlOptions xmlOptions = new XmlOptions();
xmlOptions.setSavePrettyPrint();
document.save(file, xmlOptions);