The phrase is added to ensure that a portion of the contract is construed as the parties intended.
For example, say the terms of a contract already imply some particular term. To make it clear that this is what the parties intended, they may also state that term explicitly. The problem is, if you specify a term a particular way, a party could argue that interpreting another part of the contract to mean that very same thing would render that portion of the contract redundant and therefore it should be interpreted some other way.
The phrase "for avoidance of doubt" indicates a part of an agreement that is intended to restate what another portion of the contract (often in conjunction with applicable law) already implies. The phrase is added to ensure that the restatement won't be pointed to as a way to argue that other parts of the contract should be interpreted differently than intended.
It is often used where it's superfluous and there it should be avoided because it will actually do the opposite of what's intended -- implying that what it covers is covered elsewhere when it actually isn't, possibly leading to other portions of the contract becoming ambiguous or subject to misintepretation.