Twitter was ordered to hand over documents to Elon Musk from a former executive who the billionaire said could calculate the amount of spam and bot accounts on the microblogging platform, according to a court order.