Fix while loop that was causing empty file names