My other thought is maybe you have hyperthreading enabled on a multiple core computer, and it's gone haywire. :-)
My suggestion is to start printing out $i and $j and your @array and your @ARGV at key points in the code and see
what happens as it loops thru.