As has already been pointed out your workflow is a bit unclear.
But in general if you want to create or edit existing OSM data and don’t want to do that programmatically, you use an “editor” Editors - OpenStreetMap Wiki. At least JOSM and Vespucci can read both PBF and XML format OSM data and write to XML format files.
I just created the .xml manually. The resulting .osm file can then be merged as noted above (or in my case appended).
I’ve no idea if this actually answers the question since I’m not sure if (a) you can create a .osm (xmm) file but don’t know how to create a .pbf file or (b) you are looking for a library to create a .osm or a .pbf file.
In my case the resulting file is just a .osm file not a .osc one, but either approach works.