problem writing data to txt file

Many thanks in advance for help on this. I have been struggling with this problem for a while. The write script below worked on the first few runs but is now creating only a blank text file. I also see the values in the log file that should go into the txt file, but they don't appear in the latter.

The script is below. In particular I'm getting a error message each time I call the write script:

"Writing data to a file.
An error occurred while writing the data to a file: null"

The script I'm using is:

FileWriter out = null;

try
{
session.log( "Writing data to a file." );

// Open up the file to be appended to.
out = new FileWriter( "RomanianLaws5.txt", true );

// Write out the data to the file.
out.write( dataRecord.get( "LAWNUM" ) + "\t" );
out.write( dataRecord.get( "EMITENT" ) + "\t" );
out.write( dataRecord.get( "FUNCTIE" ) + "\t" );
out.write( dataRecord.get( "TEXTOFLAW" ) + "\t" );
out.write( dataRecord.get( "DATEOFPUB" ) + "\t" );
out.write( dataRecord.get( "MODIFIEDBY" ) + "\t" );
out.write( dataRecord.get( "LONGLAWRECORD" ) + "\t" );
out.write( dataRecord.get( "REFERSTO" ) );
out.write( "\n" );

// Close up the file.
out.close();
}
catch( Exception e )
{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}

All the best,
Roger

understand the problem

With invaluable help from Todd, I have understood the problem here. Some of my values are blank, but the FileWriter cannot accept null values. This requires two modifications: First, the statements-

String nullToEmptyString( String value )
{
if( value==null )
{
return "";
}

return value;

before the Filewriter script. Then, instead of out.write( datarecord.get....), the command
out.write( nullToEmptyString( session.getVariable( "XXXX" ) ) + "\t" );
is used.