Expect the unexpected! 

save_state("RUNNING");

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

    open my $fh, '>', $state_file
        or die "open($state_file): $!";

    print $fh $state
        or die "print($state_file): $!";

    close($fh)
        or die "close($state_file): $!";
}