You are so very very close.
You just needed to specify that the file is opened in "write" mode.
I've updated you script, adding some error checking and comments.
Code:
Break ON
$=SetOption("Explicit","ON")
$=SetOption("WrapAtEOL","ON")
$=SetOption("ASCII","ON")
Dim $sBaseDir
Dim $sDirEnt
Dim $Handle
Dim $sOutput
$Handle = FreeFileHandle()
$sOutput="KATEGORIEN.TXT"
$sBaseDir="C:\WINNT\"
; WriteLine() will *always* append to an existing file, so you must
; explicitly delete it if you want to overwrite an existing file.
If Exist($sOutput) Del $sOutput EndIf
; Mode "1" will create a file if it does not exist, but you will also need
; to specify that you want write access otherwise the file will be opened in
; the default read access mode. Write mode is "4" - see Open() in the manual
; for all acceptable modes.
If Open($Handle, $sOutput, 1+4)
; Handle file open errors
"Sorry, could not open '"+$sOutput+"' for writing."+@CRLF
"Error: ["+@ERROR+"] "+@SERROR+@CRLF
Exit @ERROR
EndIf
$sDirEnt=Dir($sBaseDir)
While $sDirEnt <> "" And @ERROR = 0
If ($sDirEnt <> ".") And ($sDirEnt <> "..") And (GetFileAttr($sBaseDir+"\"+$sDirEnt) & 16)
$=WriteLine($Handle, $sDirEnt+@CRLF)
EndIf
$sDirEnt = Dir()
Loop
; If you are not interested in the return value of a function, silence the "0" or "1" that would
; appear on the screen by assigning it to a dummy variable. Most people use the "$" variable.
$=Close($Handle)
Exit 0