Hello,
I'm neither an apache expert nor cgi/perl expert but I do know that if a DIR or file are given the required permissions, things should work.
I have a perl script which creates an htpasswd file to add username/password combos to it. All is working fine, the file of course gets created...