What’s wrong with this code? 

save_state("RUNNING");

sub save_state {
    my($state) = @_;

    open my $fh, '>', $state_file;
    print $fh $state;
    close($fh);
}