To log errors in a file, you can use the following:
jimport('joomla.log.log');
JLog::addLogger(
array(
'text_file' => 'mod_mymodule.errors.php'
),
JLog::ALL,
'mod_mymodule'
);
This will create the following and save all the error there:
root/logs/mod_mymodule.errors.php
You can, of course, change mod_mymodule to whatever you want.
Hope this helps