Hi
Absolutely you can do this - many webcams have a motion sensor that lets you record only when movement is detected. Or, if you don't mind - you can just let it run all night.
Just make sure there is no 'max recording time' set up - and you should be good. You can get a decent webcam for $50 or so
Good luck
