In rather formal or written English, would is sometimes used to talk about past habits.
In general it is safer to say used to.
Please explain to me how is it safer ??? (I need some examples in some contexts)
i'm not a teacher.
I think the main reason lies in that "would", in the sense of "predictability", is mainly used in historical or fictional descriptions of characteristic, habitual behaviour. for example,"In his last years, the King would spend whole days in morose solitude, speaking only to his immediate family and refusing all official audiences. at such times he would behave with the utmost churlishness to his ministers, and would fly into a violent rage whenever his will was crossed." in its role of describing habitual events in the past, this "would" overlaps in function with "used to". But "would" has many other meanings, too. for example, "Sama was my benefactor, and would become my guardian for the next decade", here, "would" is used as a future-in-the-past auxiliary. ie, the same word form indicates different meanings.
On the other hand, "used to" is a special auxiliary used to indicate past habit or state. for example:"i used to go for a swim every day".
as you wrote, "In rather formal or written English, would is sometimes used to talk about past habits"; that is to say, when used to indicate past habit, "would" is used less frequently than "used to"