RECORD FILE behaves strangely with FastAGI

I am trying to develop an AGI application using Visual Studio 2005. I started with STREAM FILE and GET DATA and they work fine, but I have a problem with RECORD FILE, I believe my syntax is wrong. I get all sorts of problems - application is stuck, different errors returned from asterisk and so on, and the result is always an empty file.

logger.c: AGI Rx << RECORD FILE iftach wav "#" 5000 0 BEEP M
logger.c:     -- <SIP/202-08eef048> Playing 'beep' (language 'he')
logger.c: AGI Tx >> 200 result=0 (timeout) endpos=0
logger.c: AGI Rx << RECORD FILE gave the unexpected reply of 200 result=0 (timeout) endpos=0M
logger.c: AGI Tx >> 520-Invalid command syntax. 

The “M” is underlined on the display, I gather this is a CTRL-M. Same thing happens if I do this:
RECORD FILE iftach wav # 5000 0 BEEP

Sometimes I get this error:

logger.c: AGI Rx << temp buffer RECORD FILE iftach-test wav # 5000 BEEP - errno Resource temporarily unavailable

Notice that here the is no CTRL-M at the end of the line.

Is this my problem or is something wrong with Asterisk? My installed version is