diff --git a/climax/main/preprocess_ERA5.py b/climax/main/preprocess_ERA5.py
index 19a76de09ecdf203d8f42b94a2ff05279a9acf79..0a71d97120fc71f123c3839c90207543e7ba7641 100644
--- a/climax/main/preprocess_ERA5.py
+++ b/climax/main/preprocess_ERA5.py
@@ -95,12 +95,15 @@ if __name__ == '__main__':
                 var.encoding['complevel'] = 5
 
             # save aggregated netcdf file
+            tmp = filename.parent.joinpath(filename.name.replace('.nc',
+                                                                 '_tmp.nc'))
             LOGGER.info('Compressing NetCDF: {}'.format(filename))
-            ds.to_netcdf(filename, engine='h5netcdf')
+            ds.to_netcdf(tmp, engine='h5netcdf')
 
             # reproject and resample to target grid
-            reproject_cdo(args.grid, filename, filename, mode=args.mode,
+            reproject_cdo(args.grid, tmp, filename, mode=args.mode,
                           overwrite=args.overwrite)
+            tmp.unlink()
 
     else:
         LOGGER.info('{} does not exist.'.format(str(args.source)))