I started having this issue when I took the GetParameterAsText away from a parameter that was defined as an output, derived parameter. To be clear, I started writing this script as having a user defined output parameter for an Excel file output, but then figured it would be better to have it as a defined output parameter.
At the top of my script I always had this:
Out_Excel_File = arcpy.GetParameterAsText(1)
if Out_Excel_File == '#' or not Out_Excel_File:
Out_Excel_File = "\\\\w-gis-portal\\e$\\Projects\\DRT\\InExcel_Layer_TableToExcel.xls" # provide a default value if unspecified
But at the bottom of my script I started using this:
arcpy.TableToExcel_conversion(InExcel_Layer, Out_Excel_File)
arcpy.SetParameterAsText(1, Out_Excel_File)
So I figured I didn't need the first 2 lines where I set Out_Excel_File at the top of the script, and I remarked them out. But doing that triggered an 'UnboundLocalError'. Resetting them as active code allowed the script to run without error though, so I'm moving forward with what you see here.
Hope this helps someone.