my ($basepath, $filename, $first_written);