Builds an XML DOM object and writes to a file