trim file name before attempting to write