Just a quick guess...
Do not increase the counter if you delete a line. When you delete a line the next line becomes the old line number
Use if (!* !iswm $line(@test,%count)). No need to $gettok then.
Use /filter and do it all in one shot. /filter -ww @test @test !*