There is no rule for avoiding it. However, as with all words, you should avoid repetition and make sure your text is readable. Your first sentence is perfectly fine. Just make sure you choose different words to refer to something. If you're talking about Obama, you shouldn't repeat the word Obama all the time. Instead, vary by using the President of the US, the head of state, POTUS or even words such as the man, he, leader and so on.
What follows is a bit more explanation on varying in word choice in texts by using referential words:
The word it as used in your sentence is what we call an anaphor. This means that it is a word referring back to something mentioned earlier in the text. The other two types of 'phor' are the cataphor (referring to something mentioned after the cataphor itself) and the exophor (referring to something outside the text.
Now, anaphors in particular are used to avoid repetition of the same word in your text. You replace a mentioned word, phrase or entire clause with synonyms, pronouns or anything else that could possibly express the same meaning. Let me give you an example:
- I dropped my phone. It broke.
- I sang a song, and that was not appreciated by the audience.
Anaphors are used in order to keep a certain part of the text in the reader's mind. For example, if you introduce someone by name in the first paragraph of a text, you cannot all of a sudden refer to that person again using he or she after 100 lines of text if you did not continue on that subject and kept using anaphors to keep that person in your reader's mind. If you then want to talk about that person again, you could use for example:
The person we talked about in the first paragraph.
The longer the distance between the anaphor and the referent, the more explicit you will have to be. The short example sentences I gave above could use it and that. This is because their referents were very close, meaning that not much explicitation is needed to bring the referent back tot he readers mind.
Other than anaphors, you can also use words that link the context in order to keep your text flowing:
I dropped my phone. Its screen cracked. I now won't be able to access my contacts.
Though these words are not synonyms, they refer to each other. Without the first phrase, the second and third ones wouldn't make much sense. The words in bold in the second and third sentence remind the user that we are talking about my phone still.