I see you have it set to run whether user logged in or not, so possibly running scheduled task when not logged in.
Not sure if this is your issue, but may be related to this line:
docFolder = r"Q:\2023\IMPORTED TO GIS"
Only the local drives (C:\) exist when no user is logged in. The mapped drives are user specific, so when nobody is logged in, the Q: drive doesn't exist.
Try using the UNC paths for everything other than local drives and see if it helps.
Also, unless you specifically created it, don't think this path would be valid either:
arcpy.env.workspace = r'C:\Users\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'
Normally, would have a username in there:
arcpy.env.workspace = r'C:\Users\UserName\AppData\Roaming\Esri\ArcGISPro\Favorites\test.sde'
R_