Sketchup's UI API UI.open_panel(), and save_panel() etc
Then folder=File.dirname(model.path) etc
Read both the API, AND the general Ruby File/Dir stuff together...
You don't need to use Dir.chdir() if you give File.new(fpath, 'w') the full-path to the file... which you can of course pre-assemble from the model's directory path and the new file's name, thus
fpath=File.join(File.dirname(model.path), 'my.map')
Of course you can check that the model has been saved and therefore not model.path.empty? before proceeding etc...