If Jesus went to desert alone for forty days and forty nights, how could the apostles write about it?
It's not written in any of the four gospels (Matthew, Mark, Luke, John) that Jesus was alone. Someone in a comment below prior to this edit referenced a hymn called "Jesus walked this lonesome valley" - this is an assumption by the composer. Aside from Satan's obvious presence, no further information is given about other witnesses of the event - we could theorize that someone, or even many someones, were present, Jesus was alone and told his disciples the events afterwards, or that he was alone and the Spirit provided the Gospel writers this info. All we have is what is written in the gospels, anything else is just supposition.
Mark's Gospel says that Jesus was ministered by angels, so clearly he was not alone with Satan:
Mark 1:13: And he was there in the wilderness forty days, tempted of Satan; and was with the wild beasts; and the angels ministered unto him.
The Gospels of Matthew and Luke, influenced by the hypothetical 'Q' document, does not mention the angels and appear to preclude them, since Satan was able to take Jesus up to a mountain and to the top of the temple, without their intervention. Nevertheless, we may interpret these accounts as allowing the angels to be present.
However, it seems unlikely that the angels told the evangelists or their sources about the temptations.