Make sure output stream are closed when writing out catalog.xml