[1.2.18] Wrong steps in extensions.conf?

Hello,

Sometimes, when a call comes in from the PSTN through our VoIP gateway, the information that is sent to our web page that logs calls includes the original CID name instead of the one that is we expect to be rewritten on the fly using Asterisk's LookupCIDName:
;extensions.conf
[internal]
exten => group,1,LookupCIDName
exten => group,n,AGI(web.agi|${CALLERID(num)}|${CALLERID(name)})
exten => group,n,Dial(${EXT204})
=========
;/var/lib/asterisk/agi-bin/web.agi 
#!/usr/bin/perl

#use LWP::Simple;
use URI::Escape;
use LWP 5.64;

open STDOUT, '>/dev/null'; 
#Causes double entry?
fork and exit; 

my $cidnum = $ARGV[0]; 
my $cidname = $ARGV[1]; 

$safe_cidname = uri_escape($cidname);

my $browser = LWP::UserAgent->new;

my $url = "http://www.acme.com/input.php?";
$url .= "name=" . $safe_cidname . "&";
$url .= "number=" . $cidnum . "&";

($min, $hrs, $day, $month, $year) = (localtime) [1,2,3,4,5];
$currentdate = sprintf("%02d/%02d/%02d", $day, $month+1, $year % 100);
$currenttime = sprintf("%02d:%02d", $hrs,$min);
$url .= "date=" . $currentdate . "&";
$url .= "time=" . $currenttime;
#print $url . "\n";

my $response = $browser->get( $url );
die "Can't get $url -- ", $response->status_line unless $response->is_success;
print $response->content;

Could it be that, sometimes, Asterisk doesn’t wait for the previous step to be completed before moving on to the next?

Thank you.