When it moves each item, you're changing the order of the selected items - what used to be 1 is now 0, etc. - so it ends up missing some of them in the shuffle.
Try looping through all of the selected items first and putting them in a table, then moving all of the items in the table afterward:
Code:
local items = {}
for i = 0, reaper.CountSelectedMediaItems(0) do
items[i] = reaper.GetSelectedMediaItem(0, i)
end
for i = 0, #items do
reaper.MoveMediaItemToTrack(items[i],track)
end