After the first loop, you've already read the whole FM file, so it is at EOF, so on the second, etc pass there's nothing to read. To fix this, either do a seek to the beginning right before the inner while loop, or open/read/close FM entirely within the outer loop.
BUT, also question whether or not you HAVE to be re-reading FM every time from disk in the inner loop -- can you just dump the whole thing into an array in memory before the outer loop runs? If so, it will be very much faster...