Only close file object if we are really dealing with file object. fixes #121