BUGFIX:Writing intermediate files taken out of processing loop