How do I write KVL in this circuit?
By the passive reference convention, the current enters the positive terminal of a passive element such as a resistor.  The voltage source polarity is given by the symbol.

So, KVL clockwise around loop 1 is:

\$U_{AB} - E_5 - I_2 \cdot R_2 - E_1 - I_1 \cdot R_1 = 0\$

Or,

\$U_{AB} = E_5 + I_2 \cdot R_2 + E_1 + I_1 \cdot R_1\$

Consider how you would measure the voltage across R2. How do you choose which polarity to measure? You have a choice of where to place the red and black leads so which one is correct? Obviously, both are. If the red lead is on placed on the more positive lead of the resistor, the measured voltage will be positive. If the red lead is placed on the more negative lead, the measured voltage will be negative. Choosing the reference polarity of the voltage variable (the variable you solve for in your equations) for R2 works in exactly the same way.

You are free to choose the reference polarity and, after you solve the equations, if you find that the voltage across R2 is negative, you know that the end you chose to be positive is actually the more negative end. The point is, just as with the voltmeter leads, the reference polarity is arbitrary. However, it is always a good practice to use the passive reference convention so, as in your example, if you want the voltage across R2 in terms of I2, you should should choose your reference polarity such that I2 enters the positive terminal.