Twilight knew the real answers on the Desmonds' tests because the other spy was bad at fully erasing the answers, so he could see enough traces of the original answers to know what they were. Also tonitrus bolts weren't for overall class placement, they were for failing the tests, so even if Anya was at the bottom, but still passed them all barely, she'd be safe.