Every type of file has its own internal format - a set of rules about what has to go where to define the information it is meant to represent. Usually the file extension ('.pdf' in this case) is set to tell you what internal format a file uses, but there's no absolute guarantee of that.
If you write a string to a file with Python, the file will have exactly what you put in it, in this case just the five ASCII characters H, e, l, l and o. That would correspond to the normal format for a text file. So in this case, you have created a text file but put a '.pdf' extension on it. Its internal format is still a text file, and if you rename it to 'file.txt', you'll find you can open it just fine (with a text editor).
If you want to create a true PDF file (something with the correct internal format for a PDF), you would need to use a specialized package that can write that type of file. @gsamaras and @rasmus-lyngdal-christensen gave some good suggestions (Reportlab, PyPDF2 and fpdf).