I had a problem vaguely like that that turned out to be in one case an icon and in another case an oddly placed window.
Try this. Open a Finder window and look at the contents of your desktop in list view. Compare that to the icons that show up on the desktop if there is seemingly one or more icons in list view of the Desktop folder that may be the cluprit. Delete it or move it elsewhere.
Close or hide all windows on the desktop. Tap Command w. See if the line disappears.
Quit out of all open applications, ALL of them. Tap Command Tab. Is there anything in the list besides Finder?
Change your desktop background to an Apple supplied picture, and try a solid color (one light, one dark) see if the line vanishes. It might be a part of your desktop background, though that is less likely if it shows up in other apps.
Boot the Mac in safe mode. If the line disappears it is something that you installed that runs automatically and puts that line there. Start removing startup items.