Save a file with filename prompt from script?
After a bit of research, I found a solution for you.

To fix your issue, simply pass the value 'INVOKE_AREA' into save_mainfile, bpy.ops.wm.save_mainfile('INVOKE_AREA'). This will open a file selector if the file is not saved, otherwise it will bring up a prompt that confirms the user wishes to save over the file. If you want to avoid the confirm dialog, you will need to call save_mainfile without 'INVOKE AREA'.

Passing 'INVOKE AREA' defines the operator context, which allows save_mainfile to bring up the file selector.