What is the purpose of this thin metal wire? It attaches to a nailhead on the other stud, which is securing an electrical box.
Is this a grounding wire or something else?
I believe it is as you surmised an ground wire for the houses (old?) electrical system. My first thought was wire for the exterior wall stucco, but there would have been several levels of wire.
This type of ground wire would have been typical for a 1950's residence.