You can’t use Arrayformula with a custom script.
Check out the script I wrote in this post and write a custom one for your case so that it can copy to the new rows.