Not closing file if passing in a file instead of a filename