A good idea when writing to a file is to include a space between the filename and the direction symbol. Like this:
open(FH, "> sample.txt") or die("Cannot write to file: $!\n");
Perl will ignore the extra space between the '>' and the filename. It is useful in preventing unexpected results.
-DigitalKitty