When you appendChild(mybr)
and the mybr
is already in the DOM, it will be moved to the new location. The fix is to create a new <br/>
everytime you need to insert one:
buttons = buttons + 1;
if (buttons == 2) {
buttons = 0;
document.body.appendChild(document.createElement('br'));
}