Check if a file is already closed before closing it again