A simple test script here:
while read LINE; do LINECOUNT=$(($LINECOUNT+1)) if [[ $(($LINECOUNT % 1000)) -eq 0 ]]; then echo $LINECOUNT; fi do
Not really sure what your script is supposed to do. So this might not be an answer to your question but more of a generic tip.
Don't cat your file and pipe it to your script, instead when reading from a file with a bash script do it like this:
cat
while read line do echo $line done