BKE_bpath_absolute_convert: basedir='', this is a bug
You're assigning to fname but then you're using filename in the next line. Same for tempFolder and tempfolder. This runs without error:

import bpy
import os 
import tempfile

filename = bpy.path.basename(bpy.context.blend_data.filepath)
fname = os.path.splitext(filename)[0]
tempfolder = tempfile.gettempdir()
finalpath = os.path.join(tempfolder, fname)
bpy.ops.wm.save_as_mainfile(filepath=finalpath, copy=True)