“All but X” is an idiom in (at least American) English which means essentially “99%”. So in this case it didn’t literally cure his insomnia, but is so close to having done so that it may as well have.
“X is all but Y”
Interpretation 1: X has moved so close to Y that it may as well be Y
-> X loosely equals Y
(I think this is the colloquial understanding)
Interpretation 2: In the set that represents X, Y has been removed
-> X is not Y
Excuse the poor notation, I hope this is clear! The tldr is this confuses me too sometimesEdit, eh your explanation probably explains it better anyway :)