The poet thinks it is unfair that wicked people prosper (see Psalm 72:7) and feels upset about it.
The psalmist almost strayed from the path of wisdom and godliness (see Psalm 17:5; 37:31), but God prevented him from completely losing his way (38:16; 66:9; 94:18; 121:3).
when I saw the prosperity of the wicked: Compare Psalm 72:3, 7.