You have to submit the package id if the pair (moduleName, templateName) is not unique among all DAML-LF packages uploaded to the ledger. I would generally recommend that you always include the package id for production applications but for testing and debugging it’s of course totally fine to omit it.
As for getting access to the package id, if you can I would recommend to use the JavaScript codegen which will automatically include this on all requests. If that is not an option for whatever reason, you can use daml damlc inspect-jar --json .daml/dist/mydar.dar to print out the package id. The main_package_id in there is the one of your current project but you also get the package id of your dependencies. If you want to extract it automatically, something like jq or your favorite JSON library will do the job.
I prefer having it in a separate command with machine-readable output as opposed to trying to add more output to a command that does not produce machine readable output. That just means people will start relying on the current output format of daml build and parse it via grep or whatever else which is guaranteed to break at some point.