in reply to strange behaviour with Device::SerialPort

  1. use the three-argument form of open
  2. use lexical filehandles, not globals (you don't know what other code is playing with global globs named L)
  3. display the system's error message (from $!)

open(my $log_handle, '>>', $filename) or die "can't open log file \"$filename\" for appending: $!";

As in:

#! /usr/bin/perl use strict; use warnings; my $filename = "logfile.log"; my $string = scalar localtime; open(my $log_handle, '>>', $filename) or die "can't open log file \"$filename\" for appending: $!"; print $log_handle $string; close $log_handle; # or let $log_handle fall out of scope