Remember that the getId() function from a Spreadsheet object returns a different id compared with getId() from File object, even if the File (that is managed from DriveApp) is the same spreadsheet.
Anyhow, if you open a file from DriveApp using the id provided by the Spreadsheet, you will obtain the correct File object, returning - with getId() - the "File" id, which is different from the one that you used to open the File.
It seems confusing, but it works so. I had some issues in some scripts coming from this "double" id for the same thing.