%scratchworkspace% is not resolved by the Python script. Instead it is set when passed as a tool input through ArcGIS Desktop or Server.

I.E. if you have a tool parameter, say scratch_dir and set it to %scratchworkspace% within the ArcGIS environment before you run the tool, accessing scratch_dir would give you the directory path (e.g. arcgisjobs\etc...).