Everyday Mysteries has an extensive and interesting discussion about possible origins of this expression. It mentions that an often quoted incorrect source was that the animals would huddle in thatched roofs during storms and be washed out. The roofs were water resistant and sloped to allow water to run off. The animals would have to be on the top of the roof, and that is an unlikely place to seek shelter.