This is a useless use of cat. In this case the useless cat doesn't just waste CPU time, it also prevents variables from being modified because the things after the pipe execute in a subshell. Remove the useless cat and it should work:
filename=$1
count=0
while read -r line
do
printf "%5d:%s\n" $count "$line"
count=$((count + 1))
done < $filename
echo " $count "