Check, e.g. with a print, if fileout and filepath are defined and are set to what you expect.
fileout
filepath