It's important not too append the children items to the end of $items array because: 
If $item is marked to be hidden (is_item_marked_for_skip) it's children would bet added to the last place in the menu. By creating the new $new_items array, children are added in the same place as the $item (effectively replacing it).