Instead of trying to make sendmail run as you (a practice frought with peril), I suggest you
change the permissions of your file so that Sendmail can write to it. Consult the UNIX manpages
on chgrp and chown to learn how to do this.
In the meantime, put an "or die $!" after that open() statement,
as a bare minimum...