This is the reason a try/catch block is often ill-advised. Your error was not that the file could not be opened, but instead that this line was throwing an error:
f.write(student + "\n")
+ does not append a dictionary (
student) and a string (
\n). Your try/catch block is reporting this as an open file error.