Is it possible to script what applications should open certain file extensions?
As far as I know, all file associations are defined on the launchservices.secure.plist file.

For macOS Mojave/Catalina this file is located at: 

~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist


You can read the file contents using: 

defaults read ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist


This command will output on terminal the file contents, which has each associated application with the corresponding file types. 

Sample output:

$ defaults read ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

{
    LSHandlers =     (
                {
            LSHandlerContentType = "public.3gpp";
            LSHandlerPreferredVersions =             {
                LSHandlerRoleAll = "-";
            };
            LSHandlerRoleAll = "com.colliderli.iina";
        },
                {
            LSHandlerContentType = "org.7-zip.7-zip-archive";
            LSHandlerPreferredVersions =             {
                LSHandlerRoleViewer = "-";
            };
            LSHandlerRoleViewer = "com.aone.keka";
        },
                {
            LSHandlerPreferredVersions =             {
                LSHandlerRoleAll = "-";
            };
            LSHandlerRoleAll = "com.apple.dt.xcode";
            LSHandlerURLScheme = xcpref;
        },
                {
            LSHandlerContentType = "public.html";
            LSHandlerPreferredVersions =             {
                LSHandlerRoleAll = "-";
            };
            LSHandlerRoleAll = "com.apple.safari";
        }
    );
}


I cannot fully answer your question now, but this is the starting point to look at and understand how those parameters works, and after testing and figuring it out we can expand this information with complete details and some examples of edited working versions.



But for the specific situation, considering the case of making a kind of template to just to replicate, (or to have it stored as a backup):

I suggest you could manually customize one system the way you want it, by traditional Finder file associations methods, and once it is fine, you save that .plist file, then you can replace that .plist file on the new system, or on the new user profile, and [reboot?, logout?, or kill finder?] and login again, and this should be enough for the associations be replicated and ready.

[Comments and edits are welcome]