One way to do this would be for the non-cron script to remove the production file when it first starts, write to a temporary file, then when it's done its work, copy the temp file to the prod file location. In the example code, the temp file will be removed by default when the script finishes.
Then, in the script that attempts to read the file at 5pm, have it loop and sleep until the prod file exists:
The script that writes the file:
use strict;
use warnings;
use File::Copy;
use File::Temp qw(tempfile);
my $prod_file = 'prod_dir/prod.txt';
unlink $prod_file or die $! if -e $prod_file;
my $tfh = File::Temp->new(UNLINK => 1);
while (...){
...;
print $tfh "whatever\n";
}
copy $tfh->filename, $prod_file or die $!;
The script that reads the file at 1700 hrs:
use strict;
use warnings;
my $file = 'prod_dir/prod.txt';
while (! -e $file){
sleep 10;
}
open my $fh, '<', $file or die $!;
while (<$fh>){
...; # do stuff
}