If the average residual power at the line frequency after polynomial fitting (mean_score) is negative on the first iteration, the function will return data that has already been modified by dss_line(), even though the stopping criterion suggests the artifact wasn't actually present or the denoising made things worse.
I suggest retaining a copy of the input, which is returned if the mean_score is negative on iteration 0.