Fixed fopen error handling