Code:
#include <windows.h>
#include <tchar.h>

int _tmain()
{
	HANDLE hf;
	hf = CreateFile(TEXT("AAA.txt"),GENERIC_WRITE,NULL,NULL,OPEN_ALWAYS,NULL,NULL);
	DWORD writtenBytes = 0;
#ifdef UNICODE
	WORD bom = 0xFEFF;
	WriteFile(hf, &bom, sizeof(bom), &writtenBytes, NULL);
#endif
	LPCTSTR line = TEXT("X Y Z\r\n");
	WriteFile(hf, line, _tcslen(line) * sizeof(TCHAR), &writtenBytes, NULL);
	line = TEXT("1 ");
	WriteFile(hf, line, _tcslen(line) * sizeof(TCHAR), &writtenBytes, NULL);
	line = TEXT("3 ");
	WriteFile(hf, line, _tcslen(line) * sizeof(TCHAR), &writtenBytes, NULL);
	line = TEXT("8\r\n");
	WriteFile(hf, line, _tcslen(line) * sizeof(TCHAR), &writtenBytes, NULL);
	CloseHandle(hf);

	return 0;
}