Optimization (faster to check flag).

Checking a flag for opening is a lot faster than checking if the
filehandle is defined. Speeds up nytprof target from 7.05s to 4.89s by dramatically cutting the number of subroutine calls.