I see two places where you perform a division, and both simply divide by
$granularity. My guess is that you didn't provide a 3rd argument to your throughput.pl command or the value you provided resolves to 0.
Basic debugging checklist
Writeup Formatting Tips