Moved file opening procedures to right after csv read in so that log file can be created with proper name