If you can build a coop that is completely predator-proof, that should be the safest place for them to sleep.
Whether trees are safe will depend on the trees and the predators. Sleeping high enough in a tree will be good protection against dogs (that cannot climb trees) but not against raccoons...