Opening, writing, and closing a file