The code you posted seems a bit frail at places, but if it works for you, we can focus on your specific question.
The main problem is that you are not adding the $menu array to your node object before saving it. You would only need to add it to the object before you save it, similar to this:
$node->menu = $menu;
...
node_save($node);
Cheers and good luck!
P.S.: You can check out this thread for some code examples http://stackoverflow.com/q/2603289/5875098https://stackoverflow.com/q/2603289/5875098 P.S.2: To get all the terms directly from the $node object:
$terms = array();
$language = 'und'; // or will be provided by some Drupal hooks
foreach ($node->field_tags[$language] as $delta => $value) {
$termObj = taxonomy_term_load($value['tid']);
$terms[] = $termObj->name;
}
You can replace the $terms = explode... in your code with this snippet.