How do I go about retrieving the page's tcm id and insert it as a comment in the page source using a Dreamweaver Template?
The easiest way is to modify the Tridion Page Template(s) to include something like this in your Dreamweaver Template Building Block:
<!-- PageId: @@Page.Id@@ -->
At publish time Tridion will resolve Page.Id to the current page's ID and output something along these lines:
<!-- PageId: tcm:123-123-64 -->
If you're not using Dreamweaver templating, or you don't want to use Tridion templates for this, then please expand on your question.