And grep -c is even more portable, because wc -l has leading spaces on *some* OS.
Likewise grep -c ^ file is perhaps less readable but portable, compared to wc -l < file .
On top of several syntactical/orthographical errors ($nidlist, $currnid, ), the entire script is way too complicated. Unless there are requirements or conditions not shown, a for loop would handle the situation much better:
for currid in "$idlist"
do printf "%s %d" $currid $(grep -c $currid path/to/file)
done | sort -k2 | head -n3
This would have the drawback that it grep s through the file n times. Doing the whole thing in e.g. awk could reduce that resource consumption by far.
---------- Post updated at 22:11 ---------- Previous update was at 21:55 ----------
Would this (as a first step, and assuming NO spaces in idlist) satisfy your needs: