sub recordTime {
   open(TIME, ">>path/to/a/text/file.txt")
                or die "Could not open file.txt to append record time: " . $!;
   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
        localtime(time);
   my $am_pm = "am";
   if ($hour > 12) {
      $am_pm = "pm";
      $hour = $hour - 12;   
   }
   printf TIME "%4d-%02d-%02d %02d:%02d:%02d %s\n",
                      $year+1900,$mon+1,$mday,$hour,$min,$sec,$am_pm;
   close(TIME);

   # append a '0' to minutes without double digits
   return $min<10 ? $hour . ":0$min $am_pm" :
                           $hour . ":$min $am_pm";
}