correction to write function for backward compatibility when format is None)