Added check for fopen failing.