in reply to Checking a header is printed already?

As AM suggests, re-factoring would not be a bad idea.

Maybe emulate, but definitely not directly use, the inner workings of CGI by implementing a wrapper sub of your own that conditionally calls CGI::header() i.e. knows whether or not it's already printed a header.

A user level that continues to overstate my experience :-))