Use output options dictionary
Updated to use custom_header in to_xml_file
More explicit error reporting