Use begin/ensure to close the file in File.open