in reply to how to write a subroutine content into a file

You call a subroutine that prints something to the default output handle, and returns 1 (because the print was successful). Then you write that 1 into FILE, which is opened to 'files.txt'.

If you want the string "How are you?\n" to be end up in the file, you need to write

print FILE "How are you?\n";

Or something along the lines of

open my $file, '>', 'files.txt'; select $file; # print to $file by default doit(); close $file; select STDOUT; # print to STDOUT again by default