After reading this question I wondered if there be statement about this on the free book Evidence-based Software Engineering.
After a quick review I was able to find a statement on chapter 6 "Reliability", section 6.4.1 "Where is the mistake?/Requirements" that seems relevant to the question of "Does having a specification result in better code?" :
There have been very few studies of the impact of the form of specification on its implementation
The 1 study linked from that statement : "The Effects of the Symbology and Spatial Arrangement of Software Documentation in a Modification Task" is from 1981
The study describes a series of experiments to evaluate the effects of the format of software documentation on programmer performance and finds that: "the more succinct the [specification] symbology, the better the performance." with performance being: "the number of errors which appeared in the first submission of the modified program". Time of implementation was also considered but in that regard succint specification symbology seemed to have no effect.
One can also find some tangentially related studies on Chapter 7 "Source code" section 7.2.3 "Desirable Characteristics/Explaining Code" showing evidence that high level models aid general human mental comprehension.
In summary I think this shows the way the specification is written, has an effect on the amount of errors the resulting code has. I believe this answer the question because, if one thinks about this carefully, having a specification is unavoidable. One can only have different forms of specification, total lack of specification of any kind would mean total lack of any goal for the coding effort, which would render any effort to measure how good the code is impossible, since there would be no goal to compare against.