Check your flow:
=================
Start at rank 15 & go down:
For each person on this rank:
assign variables, etc.
If they need to be demoted, demote them.
Print out this person's stuff.
Go to next person.
=================
Assume I am rank 10, but need to be demoted.
When your script processes everyone for rank 10, i will be demoted, but my information will still be printed.
The script then processes everyone for rank 9. I will show up with them, b/c I was just demoted.
In short, you need to structure your code so that, if an individual is demoted, than his information will not be printed out yet. You can hack this using logical (true/false) flags, or you can figure out a way to do it using a logical flow.
Either way, good luck, and I hope this was helpful.