I'm sort of with others on this. I'd be reluctant to test for file existance, or some of those other things. I think it's better to set/get a test variable when you call it for test mode.
It sounds like this isn't for public consumption (since you mentioned sticking test records in a database). If that's the case, then I'd definitely just have a test variable you can set for unit testing. This may cause you to write some wrapper subs that do the test and return strings based on whether the test was set.
Also, I'd recommend some immediate output (to log or whatever you use) indicating that the module is acting in TEST mode. You really don't want to push that out to prod and end up with test crap in your database.
--
I used to drive a Heisenbergmobile, but everyone I looked at the speedometer, I got lost.