This is a good question. Good works are a positive response to God’s grace, and by them we may merit (meaning we may be generously given, though we are not deserving) grace and an increased response to grace, so that we may grow in faith and become more holy. If one were to examine their journey of faith, it often includes works on the behalf of the believer.
For instance, the Spirit moves within them, and they seek spiritual advice or research the faith or pray more, or any number of actions that they participate in, which are a response to the grace of God in them. What if the potential believer had ignored the calling of the Spirit? Would this rejection of grace have given them faith? It is as James speaks of Abraham, who ‘merited’ (was given the undeserved gift of) a great promise from God, because he allowed God to give it by his response:
“21 Was not Abraham our father justified by works, when he offered his son Isaac upon the altar?”
Notice this work is not the OT Law that Paul speaks of in Romans, but rather a work of faith in God. What if Abraham had ‘believed’ God ‘in his heart’, but had not taken his son to be sacrificed? Would he really have believed God? Would he have become the Patriarch of the Israelites? The same can be asked of Peter: had he killed himself as Judas did, would he have been able to accept Jesus’ forgiveness?
Essentially, to me, anyway, works are our positive cooperation with God’s grace that allow us to grow closer to our Lord, in faith, hope, and charity. They are our free response to God’s free gift of grace from His love, that, if our dispositions are proper and we seek it, will allow Him to make us perfect and love Him, and others, as He desires.
I could be wrong, but this is what I feel the purpose of works are, besides obedience to Jesus Christ (though cooperating with His grace is, in itself, an act of obedience).