Q: "How do I get my pid into a file, simply?"
A: print { open my $out, ">", "pidfile"; $out or die } $$, "\n";
Yes, I like Perl.
Why not a more traditional form?
print { open my $out, ">", "pidfile" or die "$!"; $out } $$, "\n";
But yeah, that is nifty.