Do you mean a change of slugs from your internal website to the external one? Or, within a single site, the slugs are changing?
The first thing I would do is compare the "Generate description permalinks from" setting (in Admin > Settings > Global) between your two sites. If they set differently, you will end up with different slugs! See:
Additionally, running the generate slugs task (especially if you are using the --delete option when running it) can definitely cause the slugs to change. When run without --delete, it should just populate any slugs that are missing - but if you run it with that option, it will delete all existing slugs, check the value of the "Generate description permalinks from" setting, and then use that when it repopulates all slugs (though the setting just affects descriptions) in the application.
Technically, I don't think you should need to run that task as part of your scripted 2-site setup's data transfer. It should only be needed if there are issues with missing slugs in the original dataset - which you'd want to correct before copying over anyway!
More on the generate slugs task here:
Rebuilding the nested set should not affect the slugs. The nested set is used to manage ordering in hierarchies, such as in the treeview. More here:
Finally, note that we offer a similar 2-site deployment as part of our Premium+ hosting plan. We make the replication script that we use for this service publicly available, here:
It uses Ansible
to run the script as a playbook, which sounds like a different approach than what you are doing, but it might be useful to compare. From what I know (and can tell from looking at the playbook), our script copies the database, uploads and downloads directories, and the ES index (so there is no downtime on the public site during re-indexing), and restarts services afterwards.