Checking that the fopen was successful might be worth it too.