added exception handling for file writes (gzip)