.duplicate() does not update selection, crashing Illustrator
selection[0].duplicate()
// redraw()
alert(selection.length)
when running this script in Illustrator, you will see that both the original selection plus its duplicate will be selected, but the alert will display 1. Running this script in debug shows that selection only contains one object despite .duplicate() being used. This causes a corruption(?) issue where in reality there are now two objects selected but selection only shows one to be selected unless you do redraw(). This discrepancy will cause Illustrator to crash when trying to set the selection (in specific circumstances) on another line after the .duplicate().
In other situations, whether one or two objects are selected after script execution is finished depends on whether you run the script in Illustrator or in debug. This makes it quite hard to be a developer.
.duplicate() needs to be fixed to immediately update selection when executed. using redraw() is not an ideal solution.