There is but one name under heaven, by which man may be saved. Every man with volition has the ability to choose in his thinking, to think and act through faith in Christ, or independently of faith in Christ.
This initial issue is primary or fundamental to performing any work.
The same issue is involved in repentance and confession, the requirement of cleansing after baptism and later missing the mark, and demonstrated in the actions of the priests outside the Tabernacle prior to entering the Holy Place.
Our criterion for divinely righteous action is by His standards, not ours independently of Him. The work in question, might still be good in a worldly fashion, but we are not of the world, although we are in the world.
There might also be good works which He has predestined from eternity past, which logistically provide for believer and unbeliever alike. Not every good work, though, is good by Divine Standards.
This is one of the Adversary's deceptive ploys, because one consequence of the garden of Eden and Original Sin, is that man now is able to discern between good and evil. We also have enmity against the Adversary. It is easy to confuse righteousness with good and sin with evil, but these are different meanings.
For example immorality is indeed sinful, ie, it misses the mark, the target of our focus per His Plan, but not all sin is immorality. Whenever we fail to do something in a right fashion, we still have failed to perform a righteous work. If even believers perform a good work, but while out of fellowship with God, we still have not performed it through faith in Him, and our only rewards for that good work is what we might receive here in a worldly fashion.
Worse, if we continue to live outside of faith through Him, we degenerate our thinking, our mind, our soul, and then our heart, by scarring our thinking into associating that past work with a given set of circumstances, making our immediate ability to act through faith in Him in the future testing, even more difficult. We essentially scar our souls when we perform good works independent of faith through Him.