To answer this question, I started by searching for old internet references of the quote. The oldest confirmed reference of the quote was here on page 68 of the pdf. This pdf is a "public HTML draft" of the book The Art of UNIX Programming by Eric S. Raymond, p. 24.
On pg. 1, the most recent entry in the revision history is listed as "Revision 0.87; 30 June 2003; Kirk McKusick contributed a summation of the BSD lawsuit." Further below by 1 line: "Revision 0.86; 26 June 2003; Cleanup release." And further below by a further 1 line: "Revision 0.85; 24 June 2003; Review and cameos from Ken Thompson."
Assuming that the version of the manuscript is Revision 0.87, Revision 0.85 would have already included the quote as it is unrelated to the "BSD lawsuit" (UNIX System Laboratories, Inc. v. Berkeley Software Design, Inc.) and shouldn't be added as part of a "cleanup." Thus, Ken Thompson reviewed the book when it contained his quote(s; there are two of his quotes in the book). If Ken Thompson had pointed out the quote was misattributed to him, it most likely would have been removed (the dedication reads "To Ken Thompson and Dennis Ritchie, because you inspired me."). Yet, it is still in the book (i.e. wasn't removed) so it is likely the quote is correctly attributed.
@Fizz wrote
My impression is that that book is the origin of the quote. (The other books which contain the quote are more recent). Raymond's book is somewhat authoritative, but still is a pretty new book (from 2003). Either Thompson said it in private... or maybe Raymo[n]d made it up.
The internet search concurs that the quote likely originated with the book. However, the comment introduces the possibility that Thompson said it in private. Looking at Revision 0.66, the description is "Cameo quote from Brian Kernighan. Various minor corrections."
The only quote attributed to Brian Kernighan and unsourced is the following:
On the other hand, the ‘user-friendly’ GUIs of other operating systems have their own problems. Finding the right buttons to push is like playing Adventure: the interfaces are just as burdensome as any Unix command line interface, save that one can in theory find the treasure by sufficient exploration. In Unix, one needs the manual.
For this quote, the earliest web reference was, again, this manuscript. The use of another cameo quote would make it likely that the Ken Thompson quote is also a cameo quote: said to the author in private (possibly during Ken Thompson's review and starting as an offhanded discussion) and kept in the published version.