The documentation of PropertyTree is pretty bad (I've recently started improving it). What you need to do is pass a correct xml_writer_settings object to write_xml.
write_xml(filename, tree, std::locale(),
xml_writer_make_settings(' ', 4));