Guidelines for building scripts
Modularize your automation project as much as possible. Consider each script as a module. Modularizing increases the maintainability of the project.
Convert duplicate subroutines into independent scripts
If you have duplicated subroutines in different scripts, convert it into an independent script and change the subroutine call into a script call. Removing the subroutine duplication makes it easier to change the subroutine code: whenever you have to apply changes, you won't need to change every script with the duplicated subroutine.