Strange things happen when I close my laptop lid

I recently bought a new HP Spectre x360 laptop and installed Linux (Ubuntu 16.04 LTS 64 bit) for the first time.

I have noticed a few small bugs but something very strange happens when I shut the laptop lid. The last time I closed it for example, when I re-opened:

  • The screen resolution had changed to a setting I had had previously.
  • There were 5 untitled new folders on my desktop.
  • There were about 10 terminal windows opened.
  • The touchpad scrolling direction had reverted back to the default.
  • Chrome had disappeared from my toolbar when it was locked.

When I opened Chrome, it behaved like it was opened for the first time, and any extentions I had, had disappeared.
In summary, it seems like the machine had gone back in time - amongst other things.

I've also noticed previously that I've closed my lid with YouTube open, and it will start playing after I've closed it!

Is there a problem with my new laptop, or are these things bugs in my software? If it's the latter, is there anything I can do?